String
The String module provides comprehensive string manipulation capabilities for Soul, offering methods for case conversion, trimming, padding, searching, replacement, validation, and transformation. It follows a JavaScript-like API for familiar string operations.Case Manipulation
toLowerCase - Convert to lowercase
Convert string to lowercase:toUpperCase - Convert to uppercase
Convert string to uppercase:capitalize - Capitalize first letter
Capitalize the first letter and lowercase the rest:toCamelCase - Convert to camelCase
Convert string to camelCase:toSnakeCase - Convert to snake_case
Convert string to snake_case:toKebabCase - Convert to kebab-case
Convert string to kebab-case:Trimming and Padding
trim - Remove whitespace from both ends
Remove whitespace from both ends of a string:trimLeft - Remove whitespace from left
Remove whitespace from the left side:trimRight - Remove whitespace from right
Remove whitespace from the right side:padLeft - Pad string on the left
Pad string on the left to a specific length:padRight - Pad string on the right
Pad string on the right to a specific length:padCenter - Center string with padding
Center string with padding on both sides:Searching and Testing
startsWith - Check if string starts with prefix
Check if string starts with a specific prefix:endsWith - Check if string ends with suffix
Check if string ends with a specific suffix:contains - Check if string contains substring
Check if string contains a specific substring:indexOf - Find first index of substring
Find the first index of a substring:lastIndexOf - Find last index of substring
Find the last index of a substring:count - Count occurrences of substring
Count how many times a substring appears:String Manipulation
replace - Replace first occurrence
Replace the first occurrence of a substring:replaceAll - Replace all occurrences
Replace all occurrences of a substring:split - Split string into array
Split string into an array by separator:join - Join array into string
Join array elements with a separator:repeat - Repeat string n times
Repeat a string a specified number of times:reverse - Reverse string characters
Reverse the order of characters in a string:slice - Extract substring by indices
Extract a substring using start and end indices:substring - Extract substring (swaps if needed)
Extract a substring, automatically swapping indices if needed:Validation
isAlpha - Check if only letters
Check if string contains only letters:isNumeric - Check if valid number
Check if string represents a valid number:isAlphaNumeric - Check if only letters and digits
Check if string contains only letters and digits:isEmpty - Check if string is empty
Check if string is empty:isWhitespace - Check if only whitespace
Check if string contains only whitespace characters:Conversion
toNumber - Convert string to number
Convert string to a number:toCharArray - Convert to character array
Convert string to an array of characters:Utility
length - Get string length
Get the length of a string (Unicode-aware):Advanced Examples
Text Processing Pipeline
String Validation System
Text Formatting Utility
String Search and Replace Engine
Template String Processor
String Analysis Tool
Best Practices
- Unicode awareness: String operations are Unicode-aware for proper character handling
- Null safety: Methods return null for invalid inputs
- Immutability: String methods return new strings, leaving originals unchanged
- Performance: Use appropriate methods for your use case
- Validation: Always validate string inputs before processing