Promotic
WikipediaLinkedInYoutubeTwitterFacebook

StringSplit - method of object Pm

Description:
Returns a 1-dimensional array of substrings (zero-based index).
Syntax:
StringSplit(sString As String, sDelimiter As String, [sParams As String]) As Array
Calling:
aArray = Pm.StringSplit(sString, sDelimiter[, sParams])
Parameters:
sString(String) Source string expression.
sDelimiter(String) Separator, i.e. text used to identify substring boundaries.
single character string - This character will be searched in the source string (in sString) and according to that, the source will be divided into substring array.

The most commonly used separators ";" (semicolon), ":" (colon), " " (space), etc.

"" - Source string (sString) is separated into individual characters. I.e. the lenght of the returned array will be the same as source string.
"#nl" - (new line) Source string (sString) is separated to individual rows.
"#ws" - (white space) Source string (sString) is separated to individual words. I.e. the characters like "space", "new line", "tab", etc. will be used as separators and will not be present in the output substrings.
sParams[optional] (String) Entries with assigned value are separated by a semicolon, for example count:2;empty:0;
count:n; - Defines the maximum lenght of returned array.
If the parameter is not set (or the value is -1), then each separator is used for separation. I.e. all substrings are saved into the array.
If the parameter is n positive number then the method returns the maximum number of substrings
If there are less substrings, the returned array is smaller.
If there are more substrings then the substring at the end are not saved into the array.
empty:n; - Defines the way the empty string after the last separator is returned in the array of values.
empty:0; (default) - If the string ends with the separator then the last array item will be an empty substring.
empty:1; - If the string ends with the separator then the empty substring is NOT saved to the end of the array.
Note:
The method can also be called in the graphic item events for Web Panels.

The method is functional also in Macro expression $.expr.

Example:
Example for VBScript language:
Dim arr1, arr2, sValue
sValue = "Temperature=45;Pressure=1015;Power=569;"
arr1 = Pm.StringSplit(sValue, ";", "empty:1;")
  ' arr1(0) contains "Temperature=45"
  ' arr1(1) contains "Pressure=1015"
  ' arr1(2) contains "Power=569"
  ' arr1(3) does not exist because the empty string after the last semicolon is not saved ("empty:1;" is set)
arr2 = Pm.StringSplit(arr1(0), "=")
  ' arr2(0) contains "Temperature"
  ' arr2(1) contains "45"
------
Example for JavaScript language:
var arr1, arr2, sValue;
sValue = "Temperature=45;Pressure=1015;Power=569;";
arr1 = Pm.StringSplit(sValue, ";", "empty:1;");
  // arr1.GetItem(0) contains "Temperature=45"
  // arr1.GetItem(1) contains "Pressure=1015"
  // arr1.GetItem(2) contains "Power=569"
  // arr1.GetItem(3) does not exist because the empty string after the last semicolon is not saved ("empty:1;" is set)
arr2 = Pm.StringSplit(arr1.GetItem(0), "=");
  // arr2.GetItem(0) contains "Temperature"
  // arr2.GetItem(1) contains "45"
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- LN2
- PI
- Pow
- Sin
- StringSplit
 
 
- Tan
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice