| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Deletes and/or inserts characters in a string.
Stuff( <cString>, <nStart>, <nDelete>, <cInsert> ) --> cNewString
The function returns a modified copy of <cString>.
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.
| See also: | At(), HB_RegExReplace(), Left(), RAt(), Right(), StrTran(), SubStr() |
| Category: | Character functions |
| Source: | rtl\stuff.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com