Issue
I have a string that contains different ranges and I need to find their value
var str = "some text x = 1..14, y = 2..4 some text"
I used the substringBefore()
and substringAfter()
methodes to get the x and y but I can't find a way to get the values because the numbers could be one or two digits or even negative numbers.
Solution
Is this solution fit for you?
val str = "some text x = 1..14, y = 2..4 some text"
val result = str.replace(",", "").split(" ")
var x = ""; var y = ""
for (i in 0..result.count()-1) {
if (result[i] == "x") {
x = result[i+2]
} else if (result[i] == "y") {
y = result[i+2]
}
}
println(x)
println(y)
Answered By - Desmond
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.