LastIndexOf |
Top Previous Next |
The LastIndexOf Special Function Command allows you to obtain the zero based Index of the last instance of one or more specified characters within a string. Important: Special Function commands can only be used on the right hand side of a Variable Assignment command. Command Syntax
LastIndexOf,[SearchFor],[OriginalString],[StringComparison]
The comma character after the command is compulsory as are all three parameters and the commas separating them.
Parameters:
SearchFor: The string to search for within the original string OriginalString: The string to search StringComparison: A string representing a member of the StringComparison enumeration:
SearchFor and OriginalString parameters are compulsory, the StringComparison parameter is optional. If provided, the value must be one of the following:
If no StringComparison parameter is provided, the default StringComparison.Ordinal will be used.
If any required parameter is missing or invalid an error will be thrown. All parameters must be surrounded by quotation marks if one or more commas are included. It is good practice to include the quotation marks in any case, so that it reduces the risk of error when writing scripts.If the string contains no instances of the SearchFor value are located in the original string -1 will be returned. Important: Any string containing or consisting of one or more commas MUST be enclosed in double quotes, otherwise an error will be thrown. Example:
Retrieve the Index of the word The and insert the installed version number of Windows Media Player in front of it:
Var:VersionString="The Media Player File Version:" Var:Version=GetFileVersion,"C:\Program Files (x86)\Windows Media Player\wmplayer.exe" Var:VersionIndex=LastIndexOf,"Version:","%%VersionString%%" Var:Sentence=Insert,"%%VersionString%%","%%Version%%",%%VersionIndex%%
See Also: Special Functions Insert Substring GetFileVersion |