String Basics: Literals, Escape Sequences & Length
Create strings, use escape characters, and measure string length.
String Basics: Literals, Escape Sequences & Length is a free Kotlin Academy lesson on CoddyKit — lesson 1 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 Kotlin Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Strings Are Objects
String Literals
val greeting = "Hello, Kotlin!"
val empty = ""
val withSpaces = " trimmed "Escape Sequences
println("Line 1\nLine 2")
println("Col1\tCol2")
println("She said \"hello\".")
println("Path: C:\\Users")String Length
val name = "Kotlin"
println(name.length) // 6
println("".length) // 0
println(" hi ".length) // 6 (spaces count)Accessing Characters by Index
val s = "Hello"
println(s[0]) // H
println(s[4]) // o
println(s.first()) // H
println(s.last()) // oisEmpty and isBlank
println("".isEmpty()) // true
println(" ".isEmpty()) // false
println(" ".isBlank()) // true
println("hi".isBlank()) // falseString Comparison
val a = "hello"
val b = "hello"
println(a == b) // true (content)
println(a.equals(b, ignoreCase = true)) // trueSubstring
val text = "Hello, Kotlin!"
println(text.substring(7)) // Kotlin!
println(text.substring(0, 5)) // HelloindexOf and contains
val s = "Hello, Kotlin!"
println(s.indexOf("Kotlin")) // 7
println(s.contains("Hello")) // true
println("Kotlin" in s) // true (in operator)uppercase, lowercase, capitalize
val s = "hello kotlin"
println(s.uppercase()) // HELLO KOTLIN
println(s.lowercase()) // hello kotlin
println(s.replaceFirstChar { it.uppercase() })Strings Are Immutable
val s = "hello"
val upper = s.uppercase() // new string
println(s) // still "hello"
println(upper) // "HELLO"Quick Check
Recap
Frequently asked questions
Is the “String Basics: Literals, Escape Sequences & Length” lesson free?
Yes — the full text of “String Basics: Literals, Escape Sequences & Length” is free to read here on the web, and the Kotlin 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 Kotlin Academy course, upgrade to CoddyKit PRO.
What will I learn in “String Basics: Literals, Escape Sequences & Length”?
Create strings, use escape characters, and measure string length. You practise Kotlin 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 Kotlin Academy?
No prior experience is required. Kotlin Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “String Basics: Literals, Escape Sequences & Length” 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 Kotlin Academy lesson?
Yes. Every Kotlin 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.
All lessons in this course
- String Basics: Literals, Escape Sequences & Length
- String Templates: $variable and ${expression}
- Raw Strings and Triple Quotes
- Key String Functions: trim, split, replace, contains