startsWith

fun CharSequence.startsWith(char: Char, ignoreCase: Boolean = false): Boolean(source)

Returns true if this char sequence starts with the specified character.

Since Kotlin

1.0

fun CharSequence.startsWith(prefix: CharSequence, ignoreCase: Boolean = false): Boolean(source)

Returns true if this char sequence starts with the specified prefix.

Since Kotlin

1.0

fun CharSequence.startsWith(prefix: CharSequence, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this char sequence starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.0

expect fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.0

Parameters

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
}

expect fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.0

Parameters

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
}
actual fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.1

Parameters

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
}

actual fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.1

Parameters

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.

Throws

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
}
actual fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.0

Parameters

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
}

actual fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.0

Parameters

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.

Throws

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
}
actual fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.3

Parameters

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
}

actual fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.3

Parameters

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.

Throws

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
}
actual fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.8

Parameters

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
}

actual fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.8

Parameters

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.

Throws

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
}
actual fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string starts with the specified prefix.

Since Kotlin

1.8

Parameters

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
}

actual fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean(source)

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

Since Kotlin

1.8

Parameters

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.

Throws

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
}