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. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, and your progress syncs across the web and the CoddyKit app. The Kotlin Academy course includes 4 lessons in total.
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
Learn Kotlin with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “String Basics: Literals, Escape Sequences & Length” lesson free?
Yes — any 3 lessons of the Kotlin Academy learning path, including “String Basics: Literals, Escape Sequences & Length”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Kotlin Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
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