Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala function to get next letter of the alphabet

Tags:

string

scala

Looking for something to do the following:

Given input: "s"
Expected output: "t"
like image 724
Larsenal Avatar asked Jan 26 '26 22:01

Larsenal


2 Answers

scala> def f(s: String) = (s.head + 1).toChar.toString
f: (s: String)java.lang.String

scala> f("s")
res10: java.lang.String = t
like image 105
Nicolas Payette Avatar answered Jan 29 '26 13:01

Nicolas Payette


def nextLetter(x:String) = (x(0) + 1).toChar.toString
like image 38
Larsenal Avatar answered Jan 29 '26 13:01

Larsenal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!