Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/String-matching/Kotlin/string-matching.kotlin
Normal file
16
Task/String-matching/Kotlin/string-matching.kotlin
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fun main() {
|
||||
val s1 = "abracadabra"
|
||||
val s2 = "abra"
|
||||
println("$s1 begins with $s2: ${s1.startsWith(s2)}")
|
||||
println("$s1 ends with $s2: ${s1.endsWith(s2)}")
|
||||
val b = s2 in s1
|
||||
if (b) {
|
||||
print("$s1 contains $s2 at these indices: ")
|
||||
// can use indexOf to get first index or lastIndexOf to get last index
|
||||
// to get ALL indices, use a for loop or Regex
|
||||
println(
|
||||
s2.toRegex(RegexOption.LITERAL).findAll(s1).joinToString { it.range.start.toString() }
|
||||
)
|
||||
}
|
||||
else println("$s1 does not contain $2.")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue