contentEquals
infix fun CharSequence?.contentEquals(
other: CharSequence?
): Boolean
(Common source) (JVM source) (JS source) (Native source)
For Common, JS, Native
Returns true
if the contents of this char sequence are equal to the contents of the specified other,
i.e. both char sequences contain the same number of the same characters in the same order.
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals \"Kotlin\" is ${stringBuilder contentEquals "Kotlin"}") // true
stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println("\"Kotlin\".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println("\"Kotlin\".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
For JVM
Returns true
if the contents of this char sequence are equal to the contents of the specified other,
i.e. both char sequences contain the same number of the same characters in the same order.
If this CharSequence is a String and other is not null
then this function behaves the same as String.contentEquals.
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals \"Kotlin\" is ${stringBuilder contentEquals "Kotlin"}") // true
stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println("\"Kotlin\".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println("\"Kotlin\".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
fun CharSequence?.contentEquals(
other: CharSequence?,
ignoreCase: Boolean
): Boolean
(Common source) (JVM source) (JS source) (Native source)
For Common, JS, Native
Returns true
if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals \"Kotlin\" is ${stringBuilder contentEquals "Kotlin"}") // true
stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println("\"Kotlin\".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println("\"Kotlin\".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
Parameters
ignoreCase
- true
to ignore character case when comparing contents.
For JVM
Returns true
if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.
If this CharSequence is a String, other is not null
and ignoreCase is false
then this function behaves the same as String.contentEquals.
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals \"Kotlin\" is ${stringBuilder contentEquals "Kotlin"}") // true
stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println("\"Kotlin\".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println("\"Kotlin\".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
Parameters
ignoreCase
- true
to ignore character case when comparing contents.
Returns true
if this string is equal to the contents of the specified CharSequence, false
otherwise.
Note that if the CharSequence argument is a StringBuffer then the comparison may be performed in a synchronized block that acquires that StringBuffer's monitor.
Returns true
if this string is equal to the contents of the specified StringBuffer, false
otherwise.
This function compares this string and the specified StringBuffer in a synchronized block that acquires that StringBuffer's monitor.