| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Extracts a substring from a character string.
SubStr( <cString>, <nStart>, [<nCount>] ) --> cSubstring
The function returns the extracted character string.
SubStr() is a versatile function for extracting parts of a character string beginning at the position <nStart>. It is similar to functions Left() and Right(), but can extract a substring from the middle of the input string. SubStr() is often used in conjunction with At() and RAt() to find the starting position of the substring to extract.
| See also: | At(), HB_ATokens(), HB_RegEx(), Left(), RAt(), Right(), Str(), StrTran(), Stuff() |
| Category: | Character functions |
| Source: | rtl\substr.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates extraction of substrings and how
// SubStr() relates to Left() and Right().
PROCEDURE Main
LOCAL cString := "www.xHarbour.com"
? SubStr( cString, 5 ) // result: xHarbour.com
? SubStr( cString, 5, 8 ) // result: xHarbour
? SubStr( cString, 1, 3 ) // result: www
? Left( cString, 3 ) // result: www
? SubStr( cString, -3, 3 ) // result: com
? Right( cString, 3 ) // result: com
RETURN
http://www.xHarbour.com