Strings in Soul represent sequences of characters enclosed in quotes. They support various operations for text manipulation, searching, and formatting.
name = "Alice"age = 30message = "My name is " + name + " and I am " + age + " years old."// With expressionsprice = 19.99total = "The total is $" + (price * 1.1)
soul formatString(template, values) { result = template for (key, value in values) { placeholder = "{" + key + "}" result = result.replace(placeholder, value) } return result}// Usagetemplate = "Hello {name}, you are {age} years old"formatted = formatString(template, { "name": "Alice", "age": 30})// "Hello Alice, you are 30 years old"
Use appropriate quotes: Choose single or double quotes consistently
Escape special characters: Handle quotes and backslashes properly
Validate input: Check for null and empty strings
Use string methods: Leverage built-in string operations
Handle Unicode: Be aware of character encoding issues
Copy
Ask AI
// Good - safe string operationssoul safeStringOperation(str) { if (str == null) { return "" } return str.trim().toLowerCase()}// Better - comprehensive string handlingsoul processUserInput(input) { if (input == null) { return { success: false, error: "Input is null" } } if (typeof input != "string") { return { success: false, error: "Input must be a string" } } // Clean and validate input cleaned = input.trim() if (cleaned == "") { return { success: false, error: "Input cannot be empty" } } if (cleaned.length() > 1000) { return { success: false, error: "Input too long" } } return { success: true, result: cleaned }}
Strings are fundamental to most Soul applications. Use them effectively with proper validation, manipulation, and formatting to create robust text processing functionality.