Home > database >  Scala string to Char
Scala string to Char

Time:06-29

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)

CodePudding user response:

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

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