Scala Programming: Get the character (Unicode code point) at the given index within the String
Scala Programming String Exercise-2 with Solution
Write a Scala program to get the character (Unicode code point) at the given index within the String.
Sample Solution:
Scala Code:
object Scala_String {
def main(args: Array[String]): Unit = {
val str = "w3resource - Scala";
println(s"Original String : ${str}");
// codepoint at index 1
val val1 = str.codePointAt(1);
// codepoint at index 12
val val2 = str.codePointAt(9);
// prints character at index1 in string
println("Character(unicode point) = " + val1);
// prints character at index9 in string
println("Character(unicode point) = " + val2);
}
}
Sample Output:
Original String : w3resource - Scala Character(unicode point) = 51 Character(unicode point) = 101
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to get the character at the given index within a given String. Also print the length of the string.
Next: Write a Scala program to compare two strings lexicographically.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/scala-exercises/string/scala-string-exercise-2.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics