Click or drag to resize

StrTran Function

X#
Search and replace characters within a string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION StrTran(
	uTarget,
	uSearch,
	uReplace,
	uStart,
	uCount
) AS STRING CLIPPER
Request Example View Source

Parameters

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.
Remarks
Examples
This example uses StrTran() to convert a postmodern analog to a famous quotation:
X#
1cString := "To compute or not to compute?"
2? StrTran(cString, "compute", "be")
3// To be or not to be?
See Also