Click or drag to resize

Stuff Function

X#
Delete and insert characters in a string.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION Stuff(
	cTarget AS STRING,
	dwStart AS DWORD,
	dwDelete AS DWORD,
	cInsert AS STRING
) AS STRING
Request Example View Source

Parameters

cTarget
Type: String
The string into which characters are inserted and deleted.
dwStart
Type: DWord
The position in cTarget where the insertion/deletion occurs.
dwDelete
Type: DWord
The number of characters to delete.
cInsert
Type: String
The string to insert.

Return Value

Type: String
cTarget with the specified characters deleted and cInsert inserted.
Remarks
Stuff() first deletes characters from cTarget, then inserts characters into the resulting string to form the return string. Stuff() can perform the following six operations: Insert:
If dwDelete is 0, no characters are removed from cTarget. cInsert is then inserted at dwStart, and the entire string is returned.
For example, Stuff("My dog has fleas.", 12, 0, "no ") returns "My dog has no fleas." Replace:
If cInsert is the same length as dwDelete, cInsert replaces characters beginning at dwStart.
The same number of characters are deleted as are inserted, and the resulting string is the same length as the original.
For example, Stuff("My dog has fleas.", 12, 5, "bones") returns "My dog has bones." Delete:
If cInsert is a NULL_STRING, the number of characters specified by dwDelete are removed from cTarget, and the string is returned without any added characters.
For example, Stuff("My dog has fleas.", 1, 3, NULL_STRING) returns "dog has fleas." Replace and insert:
If cInsert is longer than dwDelete, all characters from dwStart up to dwDelete are replaced and the rest of cInsert is inserted. Since more characters are inserted than are deleted, the resulting string is always longer than the original.
For example, Stuff("My dog has fleas.", 8, 3, "does not have") returns "My dog does not have fleas." Replace and delete:
If the length of cInsert is less than dwDelete, more characters are deleted than inserted.
The resulting string, therefore, is shorter than the original.
For example, Stuff("My dog has fleas.", 8, 3, "is") returns "My dog is fleas." Replace and delete rest:
If dwDelete is greater than or equal to the number of characters remaining in cTarget beginning with dwStart, all remaining characters are deleted before cInsert is inserted.
For example, Stuff("My dog has fleas.", 8, 10, "is.") returns "My dog is."
Examples
These examples demonstrate the six basic operations of Stuff():
X#
 1// Insert
 2? Stuff("ABCDEF", 2, 0, "xyz")            // AxyzBCDEF
 3// Replace
 4? Stuff("ABCDEF", 2, 3, "xyz")            // AxyzEF
 5// Delete
 6? Stuff("ABCDEF", 2, 2, NULL_STRING)    // ADEF
 7// Replace and insert
 8? Stuff("ABCDEF", 2, 1, "xyz")            // AxyzCDEF
 9// Replace and delete
10? Stuff("ABCDEF", 2, 4, "xyz")            // AxyzF
11// Replace and delete rest
12? Stuff("ABCDEF", 2, 10, "xyz")        // Axyz
See Also