2

Example code:

object test {
  def main(args: Array[String]) {
    println(args(0).toChar)
  }
}

I have two arguments. The first one is a single letter, whereas the second one is a sequence of letters.

How can I convert the first string argument to Char? I tried the toChar function, but without success (error: value toChar is not a member of String).

0

1 Answer 1

1

args(0).toCharArray converts a string to an array

if you are sure you want only the first char, try args(0).head or more safely: args(0).headOption

Sign up to request clarification or add additional context in comments.

2 Comments

it would be a Array[Char] that way. the head function worked fine
Yes, i added other solutions also

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.