Click or drag to resize

StrTran Function

Search and replace characters within a string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.7
	uTarget AS USUAL := NIL,
	uSearch AS USUAL := NIL,
	uReplace AS USUAL := NIL,
	uStart AS USUAL := NIL,
	uCount AS USUAL := NIL
Request Example View Source


uTarget (Optional)
Type: Usual
The string in which to search.
uSearch (Optional)
Type: Usual
The substring for which to search.
All occurrences of <uSearch> are replaced unless <uStart> or <uCount> is specified.  Note that StrTran() replaces substrings and, therefore, does not account for whole words.
uReplace (Optional)
Type: Usual
The substring with which to replace <cSearch>.
If this argument is not specified, <cSearch> is replaced with a NULL_STRING.
uStart (Optional)
Type: Usual
The first occurrence to replace.
If this argument is omitted or 0, the default is 1.  
uCount (Optional)
Type: Usual
The number of occurrences to replace.
If this argument is not specified, the default is all.

Return Value

Type: String
A new string with the specified occurrences of <uSearch> replaced by <uReplace>.
This example uses StrTran() to convert a postmodern analog to a famous quotation:
1cString := "To compute or not to compute?"
2? StrTran(cString, "compute", "be")
3// To be or not to be?
See Also