Replacing substring occurrences with another value in a source string.

 

Syntax

function ReplaceString(sOriginal, sFrom, sTo:string; bReplaceAll, bIgnoreCase: boolean): string;

 

Parameters and return values

Parameter

Type

Value

sOriginal

string

source string;

sFrom

string

what you need to find in the source string;

sTo

string

string to replace substring occurrences;

bReplaceAll

boolean

true — replace all occurrences, false — only the first one;

bIgnoreCase

boolean

ignore the letter case. Capital and small letters are equal during the search.

 

Function result

Replaces all occurrences of a specified string with another string value.

 

Example


const
  sOriginal = 'A vacation in a foreign land,\n' +
              'Uncle Sam does the best he can.\n'
              'You''re in the army now,\n'
              'oh-oo-oh you''re in the army now.\n\n' +
              'Now you remember what the draft man said,\n' +
              'nothing to do all day but stay in bed.\n' +
              'You''re in the army now,\n'
              'oh-oo-oh you''re in the army now.';
var
  s: string;
begin
  s := 'Replace \n to CRLF: ' + CRLF + 
       ReplaceString(sOriginal, '\n', CRLF, true, false);
  mLogScript(s, '');  
end.


Script work result

[18:02:01] (Log "ReplaceString"): Replace \n to CRLF:

A vacation in a foreign land,

Uncle Sam does the best he can.

You're in the army now,

oh-oo-oh you're in the army now.

 

Now you remember what the draft man said,

nothing to do all day but stay in bed.

You're in the army now,

oh-oo-oh you're in the army now.
 

See also

CRLF
mLogScript