Gilad Susel
Gilad Susel

Reputation: 11

How do I split one string into two strings in Kotlin with "."?

Let's say I have this string:

val mainString: String = "AAA.BBB"

And now I define two children strings:

val firstString: String = ""
val secondString: String = ""

What code should I write to make firstString equals to "AAA", and secondString equals to "BBB"?

Upvotes: 1

Views: 164

Answers (1)

Paulo Buchsbaum
Paulo Buchsbaum

Reputation: 2659

The below code works for any amount of strings separated by delimiters

val texto = "111.222.333"  
val vet = texto.split(".")
for (st in vet)  println(st)

It prints

111
222
333

Upvotes: 2

Related Questions