String Operations
Strings are one of the most commonly used data types in formulas. Precision Bridge formulas give you access to all standard Python string methods, making it easy to clean, transform, and format text data during migration.
Case Conversion
.upper() and .lower()
Convert a string to all uppercase or all lowercase:
[short_description].upper()
Result: 'SERVER DOWN IN PROD'
[category].lower()
Result: 'hardware'
.title() and .capitalize()
Convert to title case (first letter of each word) or capitalize only the first character:
[full_name].title()
'john doe' becomes 'John Doe'
[comment].capitalize()
'urgent fix needed' becomes 'Urgent fix needed'
Whitespace Removal
.strip(), .lstrip(), .rstrip()
Remove leading and/or trailing whitespace (or specified characters):
[username].strip()
' admin ' becomes 'admin'
[code].lstrip('0')
'000042' becomes '42'
[path].rstrip('/')
'/api/v1/' becomes '/api/v1'
Substitution
.replace(old, new)
Replace all occurrences of a substring:
[description].replace('PROD', 'Production')
'Issue in PROD environment' becomes 'Issue in Production environment'
[phone].replace('-', '')
'555-123-4567' becomes '5551234567'
Splitting and Joining
.split(delimiter)
Split a string into a list of substrings:
[tags].split(',')
'bug,urgent,frontend' becomes ['bug', 'urgent', 'frontend']
[full_name].split(' ')[0]
Extracts the first name from 'John Doe', returning 'John'.
[full_name].split(' ')[-1]
Extracts the last name from 'John Michael Doe', returning 'Doe'.
.join(list)
Join a list of strings into a single string with a delimiter:
', '.join([tag1, tag2, tag3])
If the variables hold 'bug', 'urgent', and 'ui', the result is 'bug, urgent, ui'.
' - '.join([department, team, role])
Produces something like 'Engineering - Backend - Lead'.
Searching and Checking
.startswith(prefix) and .endswith(suffix)
Check whether a string begins or ends with a given substring:
[email].endswith('@company.com')
Returns True if the email is from the company domain.
[sys_id].startswith('INC')
Returns True if the sys_id begins with 'INC'.
.find(substring) and .index(substring)
Find the position of a substring. .find() returns -1 if not found; .index() raises an error if not found:
[description].find('error')
Returns the index of 'error' within the description, or -1 if absent.
[url].find('?')
Useful for finding query string boundaries.
.count(substring)
Count occurrences of a substring:
[description].count('error')
Returns the number of times 'error' appears in the description.
[csv_line].count(',') + 1
Estimates the number of fields in a CSV line.
The in Operator
Use in to check whether a substring exists within a string:
'bug' in [short_description].lower()
Returns True if 'bug' appears anywhere in the lowercase description.
'@' in [email]
A simple check that the email contains an @ symbol.
[status] not in 'closed,resolved,cancelled'
Returns True if the status is not one of the listed values (note: this checks for substring containment in the string, not list membership).
Zero-Padding
.zfill(width)
Pad a numeric string with leading zeros to a specified width:
str([ticket_number]).zfill(8)
'1234' becomes '00001234'.
str([month]).zfill(2)
'3' becomes '03' -- useful for date formatting.
String Concatenation
The + operator is the primary way to combine strings:
[first_name] + ' ' + [last_name]
When concatenating with non-string values, convert them first:
'Priority: ' + str([priority]) + ' - ' + [short_description]
Escape Sequences
Formulas support standard escape sequences within string literals:
| Sequence | Meaning |
|---|---|
\\ |
Literal backslash |
\n |
Newline |
\t |
Tab |
\r |
Carriage return |
Example:
[line1] + '\n' + [line2]
Combines two fields with a newline between them.
Combining Operations
String methods can be chained together for complex transformations:
[description].strip().lower().replace(' ', '_')
Trims whitespace, converts to lowercase, and replaces spaces with underscores.
[tags].split(',')[0].strip().upper()
Gets the first tag from a comma-separated string, trims it, and converts to uppercase.
[email].strip().lower()
Normalizes an email address by trimming whitespace and lowercasing.
Next Steps
- Learn about conditional expressions in Conditional Logic
- Explore list and dictionary operations in Lists, Dictionaries, and Indexing
- See all available built-in functions in Available Built-in Functions
Comments
0 comments
Please sign in to leave a comment.