SubStr2 Function | |
Extract a substring from a string, using strong typing and only two arguments.
Namespace:
XSharp.Core
Assembly:
XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax FUNCTION SubStr2(
cTarget AS STRING,
dwStart AS DWORD
) AS STRING
public static string SubStr2(
string cTarget,
uint dwStart
)
Request Example
View SourceParameters
- cTarget
- Type: String
The string from which to extract a substring. - dwStart
- Type: DWord
The starting position in cTarget. Since this argument is a WORD, it cannot be negative.
Return Value
Type:
String
The substring.
If the substring is not found, a NULL_STRING is returned.
Remarks
Substr2() is a typed version of Substr(). See Substr() for details.
Examples
These examples extract part of a name:
1LOCAL cName AS STRING
2cName := "Biff Styvesent"
3? Substr2(cName, 6)
4? Substr2(cName, SLen(cName) + 2)
This example uses Substr2() with At() and RAt() to create a function to extract a file name from a file specification:
1? FileBase("c:\prg\myfile.obj")
2FUNCTION FileBase(cFile)
3 LOCAL nPos AS DWORD
4 IF (nPos := RAt("\", cFile)) != 0
5 cFile := Substr2(cFile, nPos + 1)
6 ELSEIF (nPos := At(":", cFile)) != 0
7 cFile := Substr2(cFile, nPos + 1)
8 ENDIF
9 RETURN cFile
See Also