Stuff Function

Action

Inserts and deletes characters.

Syntax

sChanged = Stuff (sOrig, iPos, iLen, sReplace)
Variable Description
sChanged The returned string. STRING.
sOrig The string in which characters are inserted or deleted. STRING.
iPos The character position to start inserting or deleting. INTEGER.
iLen The number of characters to delete. INTEGER.
sReplace The string to insert. STRING.

Notes

Stuff deletes iLen characters from sOrig, and then writes the string sReplace into sOrig beginning at the iPos position.

  • If iLen is zero, Stuff inserts sReplace.

  • If iLen is equal to the number of characters in sReplace, Stuff replaces characters starting at iPos. The length of sOrig is unchanged.

  • If sReplace is an empty string (""), Stuff deletes iLen characters starting at iPos.

  • If the number of characters in sReplace is less than iLen, the resulting string is shorter than sOrig.

  • If iLen is greater than or equal to the number of characters in sOrig after iPos, all subsequent characters in sOrig are deleted before Stuff inserts sReplace.

Example

STRING s = "hello there"
Print (Stuff (s,7,0,"OUT ")) // prints: hello OUT there
Print (Stuff (s,7,5,"WORLD")) // prints: hello WORLD
Print (Stuff (s,6,6,"")) // prints: hello
Print (Stuff (s,1,5,"HERE")) // prints: HERE there