Search and replace characters within a string.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.7
Syntax FUNCTION StrTran(
uTarget AS USUAL := NIL,
uSearch AS USUAL := NIL,
uReplace AS USUAL := NIL,
uStart AS USUAL := NIL,
uCount AS USUAL := NIL
) AS STRING
public static string StrTran(
Usual uTarget = null,
Usual uSearch = null,
Usual uReplace = null,
Usual uStart = null,
Usual uCount = null
)
Request Example
View SourceParameters
- 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:
1cString := "To compute or not to compute?"
2? StrTran(cString, "compute", "be")
3
See Also