substr()
Cuts a string or a character of a certain length (in Bytes) out of another string.
Synopsis
string substr(string s, int pos [, int len]);
Parameters
Parameter | Description |
---|---|
s | Original string |
pos | Starting position of the string to be cut out |
len | Number of Bytes to be cut out |
Return value
Shortened string; if pos is greater than the length (in Bytes) of s, if len is smaller than 1 or if any other error occurs, an empty string is returned.
Errors
missing or incorrect arguments
Description
Cuts len Bytes out of the string s from position pos (also measured in Bytes) and returns this substring. The first Byte of the string s is pos 0, the second Byte of the string is pos 1, and so forth.
If the optional parameter is omitted, the substring returned is s from pos to the end of s.
Depending on the character type one character can have 1 or more than 1 Bytes. e.g. the Latin character "A" consists of 1 Byte, while the Chinese character "你" consists of more than one Byte.
Example
Assigns "ab" to the variable x.
main()
{
string x;
x=substr("Tabak", 1, 2);
}
Assigns "你" to the variable x.
main()
{
string x;
x=substr(" 你好Tabak", 0, 3);
/* one Chinese character consists more than one Byte. */
}
Assignment
Strings
Availability
CTRL