String Tutorials
In most of the applications, data is stored as strings and developers often need to transform the string values using string operations, regular expressions, etc.
These series of tutorials cover examples for how to work with strings in Kotlin language.
Create Strings
These tutorials will cover scenarios on how to create strings using different techniques.
Read / Print String
These tutorials will cover scenarios on how to read string from console, or print string to console.
Access
These tutorials will cover scenarios on how to create strings using different techniques.
- Kotlin – Get character at specific index in string
- Kotlin – Get first character in String
- Kotlin – Get last character in String
- Kotlin – Iterate over characters in string
- Kotlin – Iterate over words in String
Contains
These tutorials will cover scenarios like the string contains a substring, or string contains any string as substring from a list, string contains only alphabets, etc.
- Kotlin – Check if string contains only alphabets
- Kotlin – Check if string contains only alphabets and numbers
- Kotlin – Check if string contains given search string
- Kotlin – Check if string contains a value from given list
- Kotlin – Check if string contains specific character
Replacement
Replacement String Operations are those, in which we replace some characters or substrings with a new value. The following tutorials will get you started with some of the replacement operations in Kotlin.
- Kotlin – Replace substring
- Kotlin – Replace multiple spaces with single space in a string
- Kotlin – Replace character at specific position in string
Append / Concatenate / Insert
- Kotlin – Append a character to the end of a string
- Kotlin – Concatenate strings
- Kotlin – Insert character at specific index in string
Splitting
Splitting is a string operation in which input is a string containing chunks separated by delimiter. We should extract the chunks from the string as a list.
- Kotlin – Split string
- Kotlin – Split string into chunks of specific length
- Kotlin – Split string by underscore
- Kotlin – Split string by single space
- Kotlin – Split string by one or more consecutive spaces
- Kotlin – Split string by any whitespace
- Kotlin – Split string by new line
- Kotlin – Split string by comma
Sorting
Transformations
- Kotlin – Convert string to lowercase
- Kotlin – Convert string to uppercase
- Kotlin – Trim string
- Kotlin – Capitalise first character of string
- Kotlin – Repeat string N times
- Kotlin – Reverse string
Delete Operations
- Kotlin – Delete character at specific index in string
- Kotlin – Delete first character from string
- Kotlin – Delete last character from string
- Kotlin – Delete substring defined by start and end positions in string
- Kotlin – Delete specific character from string
Conversions
- Kotlin – Convert string to character array
- Kotlin – Convert character array to string
- Kotlin – Convert string to int
- Kotlin – Convert int to string
- Kotlin – Convert string to float
- Kotlin – Convert float to string
Comparison
Comparison is an action to check if two strings are equal, one string is greater than the other, or one string is less than the other.
- Kotlin – Check if two strings are equal
- Kotlin – Check if two strings are equal ignoring case
- Kotlin – Compare strings
Search
- Kotlin – Find index of substring in a string
- Kotlin – Count occurrences of a substring in a string
- Kotlin – Find index of last occurrence of substring in string
- Kotlin – Find index of Nth occurrence of substring in string
Formatting
Exceptions and Solutions
Other String Operations
The following is a list of topics that cover basic string operations in Kotlin.