1. Search by index in a string
$ Where = index ($ words, $ word );# Find the place where word appears for the first time from words. The subscript starts from 0. If the search fails,-1 is returned;
Specify where to start searching: $ where = index ($ words, $ word, 10 );# Search from 10 onwards, including 10
The final position of the substring to be searched:
Specify the maximum returned position: $ where = rindex ($ words, $ word, 10 );# Only search for characters whose subscript is 10 or earlier.
2. Process substrings
Substr Parameters: String, start subscript, and length to be intercepted (the actual length will prevail if the actual length is exceeded)
If the third parameter is omitted, it is always taken to the end of the string:
StringThe start position can be a negative value, indicating the reciprocal from the end of the string:
SubSTR can be used together with index, which is more efficient than regular expressions:
Assume thatA string is a variable. You can modify the selected part of the string. The length of the substring does not need to be the same as that of the replaced string:
UseThe binding operator operates on a part of a string:
In additionA replacement method. The return value is the substring before replacement:
3Format data with sprintf
The result is the same as that of printf, but the processed string is returned without printing:
ProcessingFinancial data example:
TheIILineIt is mainly used to execute conditional expressions, while the cyclic subject is only a placeholder and can be replaced:
4Advanced sorting
First, create your own sorting Subroutine:
Then, Call:
UFOThe operator (<=>) compares two numbers and returns 0, 1,-1:
CMPOperator to compare the string size:
EmbeddedSubroutine:
DecreaseOrdered sorting:
5,Hash sort by value:
PressMulti-value sorting: