uniStrChange()

Changes the content of a string at a specific index for a defined count of digits with a replacing string.

Synopsis

int uniStrChange( string &source, unsigned from, unsigned count, string replace);

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.

uniStrChange() 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

Changes the content "ETM Professional Control, A Siemens Company" to ETM Professional Control, A Siemens Компания.

main()
{
  /* uniStrChange changes the content of a string by changing a
  specific number
  of characters at a given position */
  int d;
  string so= "ETM Professional Control, A Siemens Company";
  unsigned fr = 36;
  unsigned co = 7;
  string re = "Компания";
  d = uniStrChange(so, fr, co, re);
  DebugN("Return value:", d, "Changed content:", so);
}

Assignment

String functions

Availability

CTRL