StringExt extension

Extensions for String class providing utility methods

Provides convenient methods for common string operations including:

  • Color conversion from hex strings
  • Text formatting (capitalize, title case)
  • Validation (email, phone)
  • Text manipulation (whitespace removal, truncation)

Usage:

// Color conversion
final color = '#FF5733'.toColor;

// Text formatting
final title = 'hello world'.toTitleCase; // 'Hello World'
final cap = 'hello'.capitalize; // 'Hello'

// Validation
final isValidEmail = 'user@example.com'.isEmail; // true
final isValidPhone = '+1234567890'.isPhone; // true

// Text manipulation
final clean = '  hello  world  '.removeWhitespace; // 'helloworld'
final short = 'Very long text'.truncate(10); // 'Very long...'
on

Properties

capitalize → String

Available on String, provided by the StringExt extension

Capitalize first letter of the string
no setter
isEmail → bool

Available on String, provided by the StringExt extension

Check if string is a valid email address
no setter
isPhone → bool

Available on String, provided by the StringExt extension

Check if string is a valid phone number
no setter
removeWhitespace → String

Available on String, provided by the StringExt extension

Remove all whitespace characters from the string
no setter
toColor → Color?

Available on String, provided by the StringExt extension

Convert hex string to Color
no setter
toTitleCase → String

Available on String, provided by the StringExt extension

Convert string to title case
no setter

Methods

truncate(int maxLength, {String suffix = '...'}) → String

Available on String, provided by the StringExt extension

Truncate string to specified length with optional suffix