Everyday String Methods
Trim, split, replace, and change case.
Everyday String Methods is a free Dart Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Strings Come With Tools
Every Dart string ships with handy methods that transform or inspect text. You call them with a dot after the string.
var s = 'hello';
var n = s.length;Strings Never Change
String methods return a new string and leave the original untouched. Dart strings are immutable, so always use the returned value.
var s = 'hi';
var loud = s.toUpperCase();Trimming Whitespace
The trim method removes spaces from both ends of a string. It is perfect for cleaning up messy user input. 🧹
var raw = ' Ada ';
var clean = raw.trim();Changing Case
Use toUpperCase and toLowerCase to switch a string's case. They are great for normalizing text before comparing it.
var s = 'Dart'.toLowerCase();Splitting Into Pieces
The split method breaks a string into a list, cutting at each separator you give it. Commas and spaces are common choices.
var parts = 'a,b,c'.split(',');Replacing Text
replaceAll swaps every match of one piece of text for another, returning the updated string. Handy for fixing or cleaning content.
var s = 'cat cat'.replaceAll('cat', 'dog');Checking Contents
The contains method asks whether a string includes a smaller piece of text, giving you back true or false.
var has = 'hello'.contains('ell');Start and End Checks
Use startsWith and endsWith to test a string's edges. They are ideal for matching prefixes like https or file extensions.
var ok = 'report.pdf'.endsWith('.pdf');Finding a Position
The indexOf method returns where a piece of text first appears, or minus one if it is not found at all.
var i = 'banana'.indexOf('na');Taking a Slice
The substring method pulls out part of a string by position. Give a start, and optionally an end, to grab the piece you need.
var s = 'abcdef'.substring(1, 4);Chain Methods Together
Because each method returns a string, you can chain them. Trim, lowercase, and replace all flow in one readable line.
var s = ' HI '.trim().toLowerCase();Quick Check
You have a string with extra spaces at both ends. Which method cleans it up?
Recap: String Methods
You met trim, split, replaceAll, contains, and substring. Remember they return new strings, so capture the result you need. 🎉
Frequently asked questions
Is the “Everyday String Methods” lesson free?
Yes — the full text of “Everyday String Methods” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Everyday String Methods”?
Trim, split, replace, and change case. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Everyday String Methods” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.