xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Stuff()

Deletes and/or inserts characters in a string.

Syntax

Stuff( <cString>, <nStart>, <nDelete>, <cInsert> ) --> cNewString

Arguments

<cString>
This parameter is the input string to modify.
<nStart>
This is a numeric value specifying the position of the first character in <cString> to begin the operation with.
<nDelete>
This is a numeric value specifying the number of characters to delete, beginning at position <nStart>, before <cInsert> is inserted into <cString>.
<cInsert>
This is a character string to insert into <cString> at position <nStart>. Its length can be smaller or larger than <nDelete>.

Return

The function returns a modified copy of <cString>.

Description

Stuff() modifies an input string by first deleting <nDelete> characters and then inserting the replacement string <cInsert>. Since <nDelete> can be in the range of 0 to Len(<cString>) and <cInsert> can be any character string, including an empty string (""), the function can perform the operations Delete, Insert, Replace or a combination of them.

Unlike function StrTran(), which searches a substring, Stuff() uses a numeric start position to perform the character string operation.

Info

See also:At(), HB_RegExReplace(), Left(), RAt(), Right(), StrTran(), SubStr()
Category: Character functions
Source:rtl\stuff.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the different character string operations
// that can be performed with Stuff()

   PROCEDURE Main
      LOCAL cString := "1234567"

      // Delete
      ? Stuff( cString, 3, 2, "" )      // result: 12567

      // Insert
      ? Stuff( cString, 3, 0, "abc" )   // result: 12abc34567

      // Replace
      ? Stuff( cString, 3, 2, "ab" )    // result: 12ab567

      // Replace and delete
      ? Stuff( cString, 3, 4, "ab" )    // result: 12ab7

      // Replace and insert
      ? Stuff( cString, 3, 2, "abcde" ) // result: 12abcde567

      // Replace and delete rest
      ? Stuff( cString, 3, 6, "abc" )   // result: 12abc

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe