iNTERFACEWARE Products Manual > Installing and Using Chameleon > Using Python Scripting > Python Scripting Examples > String Manipulation > Extracting a Single Character |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
To extract a single character from a string, refer to the character using its index. For example, the following code extracts the first character from a string (and then overwrites the string):
It is important to remember that, in Python, indexing starts at 0, not 1. The first character of a string is index 0, the second character is index 1, and so on. The simple script above is useful for converting 'MALE' and 'FEMALE' to 'M' and 'F', respectively.
|