15.4.15 String operations
15.4.15.1 StrFind
Explanation |
It is used to find the position of a particular set of characters in the string from a specific location. |
Definition |
Return value, data type: int, the location of the first matching character. If the location is not found, the length of the returned string is added by 1. StrFind (Str ChPos Set [\NotInSet]); Str, data type: string, the string to be searched. ChPos, data type: int, the starting position, starting from 1, if the location is off the boundary, an error is reported. Set, data type: string, the character set to be matched. [\NotInSet], identifier, to identify the character that cannot be matched in the character set. |
Example |
Example 1
|
15.4.15.2 StrLen
Explanation |
It is used to obtain the length of the string. |
Definition |
Return value, data type: int, the current string length, which is longer than or equal to 0. StrLen (Str); Str, data type: string, the string that requires the calculation of string length. |
Example |
Example 1
The length of the string "Robotics" is 8. |
15.4.15.3 StrMap
Explanation |
It is used to back up a string, all characters in it are replaced according to the specified mapping relationship. The mapped characters correspond one by one according to their position, and the characters that are not mapped remain the same. |
Definition |
Return value, data type: string, the replaced string. StrMap (Str, FromMap, ToMap); Str, data type: string, the original string. FromMap, data type: string, the index of the mapping. ToMap, data type: string, the value of the mapping. |
Example |
Example 1
Map the string "Robotics", and "aeiou" is respectively mapped to "AEIOU". Use restrictions: FromMap and ToMap have to match with each other and have to be of the same length. |
15.4.15.4 StrMatch
Explanation |
It is used to search in a string, starting at the specified location, search for a particular format or a string, and return the matched location. |
Definition |
Return value, data type: int, the position of the first character of the matched string, and if there is no match, the string length plus one is returned. StrMatch (Str, ChPos, Pattern); Str, data type: string, the string to be searched. ChPos, data type: int, the starting position, and if the location exceeds the length range of the string, an error is reported. Pattern, data type: string, the format string to match. |
Example |
Example 1
|
15.4.15.5 StrMemb
Explanation |
It is used to check whether a character in a string belongs to a specified character set. |
Definition |
Return value, data type: bool, true indicates that the character in the string belongs to the specified character set. Otherwise, false is returned. StrMemb (Str, ChPos, Set); Str, data type: string, the string to be checked. ChPos, data type: int, the position of the character to be checked; if it exceeds the range of the string, an error is reported. Set, data type: string, the character set to be matched. |
Example |
Example 1
The second character o is a member of the character set "aeiou" and true is returned. |
15.4.15.6 StrOrder
Explanation |
It is used to compare two strings and return the Boolean value. |
Definition |
Return value, data type: bool, when str1<=str2, return true; otherwise, false. StrOrder (Str1, Str2); Str1, data type: string, the first string value. Str2, data type: string, the second string value. |
Example |
Example 1
|
15.4.15.7 StrPart
Explanation |
It is used to truncate a part of a string to generate a new string. |
Definition |
Return value, data type: string, the truncated string, truncating a string from a specified location with a specified length. StrPart (Str, ChPos, Len); Str, data type: string, the original string of a truncated string. ChPos, data type: int, the starting position, and if it exceeds the range of the string, an error is reported. Len, data type: int, the length for truncating. |
Example |
Example 1
Truncate the string for a length of 5 bits from position 1 to get "Robot". |
15.4.15.8 StrSplit
Explanation |
It is used to split a string into an array of strings by specifying a separator |
Definition |
Return value, data type: string array, the array of strings obtained by splitting StrSplit (Str [, separator]); Str, data type: string, the original string to be split. Separator, data type: string, a separator. All characters in the string are considered as a separator and can be defaulted. If no separators exist, space can be considered as the default separator. |
Example |
The string is split into four substrings (test1 test2 test3 test4). Use restrictions:
|
15.4.15.9 StrToByte
Explanation |
StrToByte can convert a string into byte type data |
Definition |
Return value, data type: byte, the conversion result of a string. StrToByte (Str, [ trans])); Str, data type: string, the string to be converted. Trans, data type: enumeration, the mathematical binary format of the string. Available parameters include \Bin (binary), \Okt (octal), \Hex (hexadecimal), \Char (character), and the default (no parameter, decimal) |
Example |
Example 1
The string "10" is converted to byte numbers in binary, octal, decimal, and hexadecimal in order, and the results are 2, 8, 10 and 16. Example 2 Byte NumChar = StrToByte(“0”, \Char); The character "0" is converted to 48 according to the conversion relationship between characters and ASCII. Use restrictions: An error will be reported when the input string does not conform to the specified data format. |
15.4.15.10 StrToDouble
Explanation |
StrToDouble can convert a string into double type data |
Definition |
Return value, data type: double, the conversion result of a string. StrToDouble (Str); Str, data type: string, the string to be converted. |
Example |
Example 1:
Convert string "3.1415926" into double type data. Use restrictions: An error will be reported when the input string does not conform to the specified data format. |
15.4.15.11 StrToInt
Explanation |
StrToInt can convert a string into Int type data |
Definition |
Return value, data type: Int, the conversion result of a string. StrToDouble (Str); Str, data type: string, the string to be converted. |
Example |
Example 1
Convert string "99" into Int type data. Use restrictions: An error will be reported when the input string does not conform to the specified data format. |
15.4.15.12 StrToDoubleArray
Explanation |
StrToDoubleArray can convert a large number of strings double into the type of double array data |
Definition |
Return value, data type: Int, to determine whether the conversion is abnormal. -1: error, 0: normal. StrToDoubleArray(output, input, spilit); Output, data type: double array, the output of conversion results Input, data type: str string, the input of strings Spilit, data type: str string, a delimiter of Double strings |
Example |
Example 1
Use restrictions: The string allows for an extra terminator at the end In case of conversion failure or including illegal characters, it will report an error, that is, "The input string is not in Double form after segmentation" The data volume of double array should be greater than or equal to that of the data in the string; otherwise, it will report an error, that is, "The input array size is insufficient, or the array is not a one-dimensional array" |