
Cartographica uses the python language interpreter to process functions and expressions for formula manipulation. As such, the standard built-in sequence functions that deal with strings in Python are available. We are considering widening some of those functions in the future, but for now, these can be used without change to the software:
Assumption below is that stringVariable has the value "Another123"
| Function
| Example
| Result
| Notes
|
| length
| len(stringVariable)
| 10
|
|
| substring
| stringVariable[0:2]
| "An"
| The start:end format takes the starting position with a base of zero, and the ending position is the character location after the last character taken
|
| string to
| stringVariable[:2]
| "An"
| If the start is omitted, then it is presumed to be zero
|
| string from
| stringVariable[2:]
| "other123"
| If the end is omitted, then it is presumed to be the length of the string
|
| string from left
| stringVariable[-3:]
| "123"
|
Negative starting points are relative to the end of the string
|
| capitalize
| stringVariable.capitalize()
| "Another123"
|
Capitalizes the first character, lower cases everything else.
|
| lower case
| stringVariable.lower()
| "another123"
|
Converts all characters to lower case.
|
| concatenation
| stringVariable+stringVariable
| "Another123Another123"
|
Concatenates two strings together
|
| substring from string
| stringVariable[stringVariable.find('other'):]
| "other123"
|
By combining the find method and the substring intrinsic, you can pull out all characters from a starting string
|
| substring to string
| stringVariable[:stringVariable.find('other')]
| "An"
|
By combining the find method and the substring intrinsic, you can pull out all the characters up to a particular string.
|
| replace substring
| stringVariable.replace('other','one')
| "Anone123"
|
Replaces the stated substring with the new substring
|
| strip characters
| stringVariable.strip('ABC123')
| "nother"
|
Removes characters from the beginning or end of the string until the first non-matching character. Often used to remove unnecessary spaces - strip(' ').
|
| title case
| stringVariable.title()
| "Another123"
|
Capitalizes the first character of each word. If stringVariable were "a long time ago", the result would be "A Long Time Ago"
|
| upper case
| stringVariable.upper()
| "ANOTHER123"
|
Converts all characters to upper case.
|
| count characters
| stringVariable.count('1')
| 1 (numeric)
| Counts all characters that match the substring. This can be useful in fields that may have a star rating (such as '*****', wherein a .count('*) would result in the number 5 that can then be used in calculations)
|
While we don't provide access to all string functions in Python, the class methods and intrinsic functions (such as those above) are available for use in Cartographica. If you're interested in experimenting with more advanced functions, the Python reference may be useful. Keep in mind that you need to have the result return the correct value, so when using count functions, the column result should be a number or float (as an example). More complex formulae can be created by combining sequences of methods and intrinsics.