Function Stuff() Foundation

Inserts and/or deletes characters in a character string.

Syntax
Stuff(<cString>, <nStart>, <nDelete>, <cInsert>) --> cNewString
Parameters
<cString>
<cString> is a character string in which characters are inserted or deleted.
<nStart>
<nStart> is an integer numeric value which determines where (at which character position) in <cString> an insertion or deletion takes place.
<nDelete>
The numeric value <nDelete> indicates how many characters in <cString> are deleted beginning at <nStart>.
<cInsert>
<cInsert> is a character string inserted in <cString> at the position <nStart>.
Return

Stuff() returns a copy of <cString> as a character string in which <nDelete> characters are deleted and the characters <cInsert>are inserted.

Description

The character function Stuff() allows complex character string operations which perform insertions and deletions at the same time. <nDelete> characters are deleted from the initial character string <cString> beginning with the position <nStart>. Then, the character string <cInsert> is inserted, also at the position <nStart>. The resulting string is returned. The function Stuff() allows six different character string operations:

Insert: When the value for <nDelete> is zero, no characters are deleted from <cString>. <cInsert> is inserted at the position <nStart>.

Delete: When <cInsert> is a null string (""), the number of <nDelete> characters are deleted from <cString> at the position <nStart> and no characters are inserted.

Replace: When the value for <nDelete> is exactly the same as the length of <cInsert>, as many characters are deleted as are inserted. Exactly <nDelete> characters from the position <nStart> are replaced with <cInsert>.

Replace and insert: When the value for <nDelete> is less than the length of <cInsert>, fewer characters are deleted than inserted. The return value is a longer character string than the initial value.

Replace and delete: When the value for <nDelete> is greater than the length of <cInsert>, more characters are deleted than inserted. The return value is a shorter character string than the initial value.

Replace and delete rest: When the value for <nDelete> is equal to or greater than the remaining characters in <cString> starting at the position <nStart>, characters at the end of <nString>are deleted and <cInsert> is attached at the end.

Examples
Character string operations with Stuff()

// The example demonstrates operation of the function Stuff() 

PROCEDURE Main 

** Insert 
   ? Stuff( "abcdefgh", 4, 0, "123")   // result: abc123defgh 

** Delete 
   ? Stuff( "abcdefgh", 4, 2, "")      // result: abcfgh 

** Replace 
   ? Stuff( "abcdefgh", 4, 2, "12")    // result: abc12fgh 

** Replace and insert 
   ? Stuff( "abcdefgh", 4, 2, "12345") // result: abc12345fgh 

** Replace and delete 
   ? Stuff( "abcdefgh", 4, 4, "12")    // result: abc12h 

** Replace and delete rest 
   ? Stuff( "abcdefgh", 4, 6, "123" )  // result: abc123 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.