0

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)

1
  • 3
    Can't you just call indexWhere on the String directly? Commented Jun 29, 2022 at 2:22

1 Answer 1

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

scala> "str".indexWhere(_.isUpper)
res2: Int = -1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.