Post

4 followers Follow
0
Avatar

What text / string functions are available?

I am trying to find a listing of text / string manipulation functions available for use in formulas - for example to populate one column with the first six characters of text found in another column existing in a shapefile.  I have looked through the Cartographica Help file and am not able to find string / text functions - the overviews provided include only the options below:

  • Introduction to Formulas
  • Creating a Column Formula
  • Conditional Expressions
  • Mathematical functions
  • Trigonometric Functions
  • Mathematical Constants
  • Geometric Functions

I have looked through these and have not been able to find any text / string functions.  I assume they exist - your help in finding them is appreciated.  Thanks,

Antonio

Antonio Rosell Answered

Please sign in to leave a comment.

6 comments

0
Avatar

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.

Gaige B Paulsen 0 votes
Comment actions Permalink
0
Avatar

hi Gaige, I meant to write earlier to thank you for your reply - so, thank you!

One comment: it would be good to have this list of string functions added to the "functions overview" I referenced in my first post - if it wasn't for your help I don't know how I could have found these are available.

Thanks,

Antonio

Antonio Rosell 0 votes
Comment actions Permalink
0
Avatar

Hi Antonio,

  We will be updating the documentation to reflect this information.

Thanks,

-Gaige 

Gaige B Paulsen 0 votes
Comment actions Permalink
0
Avatar

Gaige,

WINDOW -> SHOW LAYER INFO:  <<-- Whilst here, when one selects a specific column and then clicks the SET FORMULA button, what would one need to enter(exactly) in order to take a column of text and convert all records in that column to UPPERCASE(or all lowercase, or all with first letter Capitalized)?

Thanks,

Eric

Eric Jarvies 0 votes
Comment actions Permalink
0
Avatar

Keeping in mind that you cannot apply a formula to the column itself, you must create a new column to apply the formula to another column, you would place the field marker there for the field you want to operate on and append ".capitalize()" to that in order to capitalize, , ".upper()" to uppercase, and ".lower()" to lowercase.

Gaige B Paulsen 0 votes
Comment actions Permalink