davidzxc574
davidzxc574

Reputation: 481

Scala string to Char

With Scala 2.12, I am trying to find index of the 1st capitalized letter from a string. Below is my code.

"strCapit".split("").indexWhere(_.toCharArray.head.isUpper)

or

"strAfte".split("").flatMap(x=>x.toCharArray).indexWhere(_.isUpper)

isUpper is used on character instead of string. So is there a way of converting elements from a collection from string directly to char as I am not able to do map(x=>x.toChar)

Upvotes: 0

Views: 192

Answers (1)

yǝsʞǝla
yǝsʞǝla

Reputation: 16412

scala> "strCapiT".indexWhere(_.isUpper)
res1: Int = 3

scala> "str".indexWhere(_.isUpper)
res2: Int = -1

Upvotes: 1

Related Questions