Core API – Kotlin Programming Language (original) (raw)
startsWith
Returns true if this char sequence starts with the specified character.
Since Kotlin
1.0
Returns true if this char sequence starts with the specified prefix.
Since Kotlin
1.0
Returns true if a substring of this char sequence starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.0
Returns true if this string starts with the specified prefix.
Since Kotlin
1.0
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.0
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}Returns true if this string starts with the specified prefix.
Since Kotlin
1.1
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.1
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
if startIndex is negative or exceeds the length of the string.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}Returns true if this string starts with the specified prefix.
Since Kotlin
1.0
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.0
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
if startIndex is negative or exceeds the length of the string.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}Returns true if this string starts with the specified prefix.
Since Kotlin
1.3
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.3
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
if startIndex is negative or exceeds the length of the string.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}Returns true if this string starts with the specified prefix.
Since Kotlin
1.8
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.8
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
if startIndex is negative or exceeds the length of the string.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}Returns true if this string starts with the specified prefix.
Since Kotlin
1.8
prefix
the prefix from which this string should start with.
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\") is ${str.startsWith("abc")}") // true
println("str.startsWith(\"ABC\") is ${str.startsWith("ABC")}") // false
println("str.startsWith(\"bcd\") is ${str.startsWith("bcd")}") // false
println("str.startsWith(\"abcdef\") is ${str.startsWith("abcdef")}") // false
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", ignoreCase = true) is ${str.startsWith("abc", ignoreCase = true)}") // true
println("str.startsWith(\"ABC\", ignoreCase = true) is ${str.startsWith("ABC", ignoreCase = true)}") // true
println("str.startsWith(\"bcd\", ignoreCase = true) is ${str.startsWith("bcd", ignoreCase = true)}") // false
//sampleEnd
}Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.
Since Kotlin
1.8
prefix
the prefix from which this string's substring beginning at startIndex should start with.
startIndex
the start index (inclusive).
ignoreCase
the flag indicating if the string characters should be compared with the prefix characters in a case-insensitive manner; by default, comparison is case-sensitive.
if startIndex is negative or exceeds the length of the string.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1) is ${str.startsWith("abc", startIndex = 1)}") // false
println("str.startsWith(\"BCD\", startIndex = 1) is ${str.startsWith("BCD", startIndex = 1)}") // false
println("str.startsWith(\"bcd\", startIndex = 1) is ${str.startsWith("bcd", startIndex = 1)}") // true
//sampleEnd
}import kotlin.test.*
fun main() {
//sampleStart
val str = "abcde"
println("str.startsWith(\"abc\", startIndex = 1, ignoreCase = true) is ${str.startsWith("abc", startIndex = 1, ignoreCase = true)}") // false
println("str.startsWith(\"bcd\", startIndex = 1, ignoreCase = true) is ${str.startsWith("bcd", startIndex = 1, ignoreCase = true)}") // true
println("str.startsWith(\"BCD\", startIndex = 1, ignoreCase = true) is ${str.startsWith("BCD", startIndex = 1, ignoreCase = true)}") // true
//sampleEnd
}