cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

String Indexing Example

String Indexing Example

Summary

This article presents an updated string indexing example.

Synopsis

This article contains an InstallScript sample that will show how you can index a string variable.

NOTE: The example will remove any leading zero characters in a given string variable.

Discussion

A string variable is an array of Unicode characters with a null terminator. You can reference individual characters within a string by specifying the string name followed by an index value within square brackets. Note that the first character in a string is in position 0.

In the example below, the function BlankLeadingZeros() uses the string indexing technique to replace leading zeros in the string representation of a number with blank characters.
//-----------------------------------------------------------
prototype BlankLeadingZeros(BYREF STRING); 
...
function BlankLeadingZeros(szString)
  INT iVal, iLength;
begin
    iVal = 0; 
    iLength = StrLengthChars (szString); 

    while (iVal < iLength) && (szString[iVal] = "0") 
        szString[iVal] = " "; 
        iVal++; 
    endwhile; 
end; 
//-----------------------------------------------------------


Additional Information

For more information on the data types used in this function, you can look at the online help document Data Types and Predefined Structures.
Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Jul 09, 2018 10:09 PM
Updated by: