String
A String variable stores a sequence of characters. It's one of the most commonly used data types for storing text values like names, descriptions, messages, or any textual content.
When to Use
Use String variables when you need to:
Store user input from text fields
Display dynamic text content
Store API responses containing text
Manage labels, titles, or descriptions
Store formatted text or messages
Examples
Simple Text Storage
"Hello, World!"
"John Doe"
"Welcome to Digia"Multi-line Text
Empty String
Common Use Cases
1. Storing User Input
When a user types into a Text Form Field, you can store that value in a String variable:
2. Displaying Dynamic Content
Use String variables to show personalized messages:
3. API Response Data
Store text data from API calls:
Working with Strings
Concatenation
Combine multiple strings together using the concat() function:
String Interpolation
Embed variables within strings:
String Operations
Use string operators to manipulate text. See the String Operations documentation for available functions:
toUpperCase()- Convert to uppercasetoLowerCase()- Convert to lowercasetrim()- Remove leading/trailing whitespacesubstring()- Extract a portion of the stringsplit()- Split string into an arrayAnd many more...
Best Practices
Initialize with default values: Set an initial value (even if it's an empty string
"") to avoid null/undefined errorsValidate user input: Always validate and sanitize string input from users
Use concat for combining strings: Use
concat()function to combine multiple strings:${concat("Hello, ", name)}Trim whitespace: Use
trim()when comparing or storing user input to remove accidental spacesHandle empty states: Check if a string is empty before using it in critical operations using
isEmpty()
Related Documentation
String Operations - All available string manipulation functions
Text Form Field - Capture user input as strings
Variables Overview - Learn about all variable types
Last updated