endsWith

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

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

Since Kotlin

1.0

fun CharSequence.endsWith(suffix: CharSequence, ignoreCase: Boolean = false): Boolean(source)

Returns true if this char sequence ends with the specified suffix.

Since Kotlin

1.0

expect fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.0

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}
actual fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.1

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}
actual fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.0

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}
actual fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.3

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}
actual fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.8

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}
actual fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean(source)

Returns true if this string ends with the specified suffix.

Since Kotlin

1.8

Parameters

suffix

the suffix with which this string should end with.

ignoreCase

the flag indicating if the string characters should be compared with the suffix characters in a case-insensitive manner; by default, comparison is case-sensitive.

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\") is ${str.endsWith("cde")}") // true
println("str.endsWith(\"CDE\") is ${str.endsWith("CDE")}") // false
println("str.endsWith(\"bcd\") is ${str.endsWith("bcd")}") // false
println("str.endsWith(\"_abcde\") is ${str.endsWith("_abcde")}") // false 
   //sampleEnd
}
import kotlin.test.*

fun main() { 
   //sampleStart 
   val str = "abcde"
println("str.endsWith(\"cde\", ignoreCase = true) is ${str.endsWith("cde", ignoreCase = true)}") // true
println("str.endsWith(\"CDE\", ignoreCase = true) is ${str.endsWith("CDE", ignoreCase = true)}") // true
println("str.endsWith(\"bcd\", ignoreCase = true) is ${str.endsWith("bcd", ignoreCase = true)}") // false 
   //sampleEnd
}