Skip to content

Instantly share code, notes, and snippets.

@hongsw
Last active September 12, 2023 15:54
Show Gist options
  • Save hongsw/956befcec2e7c5804ab9906826942a56 to your computer and use it in GitHub Desktop.
Save hongsw/956befcec2e7c5804ab9906826942a56 to your computer and use it in GitHub Desktop.
dart string functions

dart string functions

Created with <3 with dartpad.dev.

void main() {
var hello = 'Hello, 🌍!';
print(hello.toUpperCase()); // Output: "HELLO, 🌍!"
hello = 'Hello, 🌍!';
print(hello.toLowerCase()); // Output: "hello, 🌍!"
hello = ' Hello, 🌍! ';
print(hello.trim()); // Output: "Hello, 🌍!"
hello = 'Hello, 🌍!';
print(hello.startsWith('Hell')); // Output: true
hello = 'Hello, 🌍!';
print(hello.endsWith('🌍!')); // Output: true
hello = 'Hello, 🌍!';
print(hello.contains('lo')); // Output: true
hello = 'Hello, 🌍!';
print(hello.substring(0, 5)); // Output: "Hello"
hello = 'Hello, 🌍!';
print(hello.replaceFirst('Hello', 'Hi')); // Output: "Hi, 🌍!"
hello = 'Hello, Hello, 🌍!';
print(hello.replaceAll('Hello', 'Hi')); // Output: "Hi, Hi, 🌍!"
hello = 'Hello, 🌍!';
print(hello.split(', ')); // Output: ['Hello', '🌍!']
List<String> helloList = ['Hello', '🌍!'];
print(helloList.join()); // Output: Hello🌍!
hello = 'Hello, 🌍!';
print(hello.length); // Output: 11
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment