strchange()
Changes the content of a string at a specific index for a defined count of digits with a replacing string.
Synopsis
int strchange( string
&source,unsignedfrom,unsignedcount,stringreplace);
Parameters
Parameter | Description |
---|---|
source | The string to be changed. |
from | The start index in the "source" string from which the content shall be replaced/inserted, beginning with 0. |
count | The number of digits from the start index to be replaced in "source". Note that you specify the exact length of the string to be replaced. |
replace | String that should be replaced/inserted. |
Return value
If parameters are missing or incorrect, -1 is returned (e.g. the Index "from" is out of range). A returning value of 0 indicates a successful change.
Errors
Missing or incorrect arguments
Description
Changes the content of a string at a specific index for a defined count of digits with a replacing string.
The string "source" is changed by inserting the string "replace" at the index "from" and replacing a "count" of digits.
A "count" of 0 only inserts the string "replace" at the index "from" without replacing other digits.
strchange() can also be used to insert/append the string "replace" at the beginning or the end of the string "source". The value for "from" must be 0 for inserting at the beginning or must be the length of "source" ("from" = strlen(source)) for inserting at the end. To prevent digits of being replaced a "count" value of 0 is necessary.
Example
Replaces "twenty"; in the source string with "thirty";. Thus, the source string "one hundred and twenty"; becomes "one hundred and thirty";.
main()
{
string source;
source="one hundred and twenty";
strchange(source, 15, 6, "thirty");
}
Assignment
Availability
CTRL