jOasis
jOasis

Reputation: 394

Scala:Handling special encoding characters in String

I have string containing many umlauts(ä,ö,ü) and euro(€) symbol. Is there any library or existing methods that transform them to (a,o,u) and Euro(or its equivalent) respectively in Scala.

I am aware of the similar libraries in python that do the job but can't seem to find it in scala.

Consider this example : val String="Köln and München are great cities. The average bus ticket costs €4.5"

I want to be converted something like this or equivalent: "Koln and Munchen are great cities. The average bus ticket costs Euros 4.5"

Upvotes: 0

Views: 321

Answers (2)

jwvh
jwvh

Reputation: 51271

You can build your own translator with whatever rules you need to apply.

val str="Köln and München are great cities. The average bus ticket costs €4.5"

val deUm :Map[Char,String] =
  Map('ö'->"o", 'ü'->"u", '€'->"Euros ").withDefault(_.toString)

str.flatMap(deUm(_))
//res0: String = Koln and Munchen are great cities. The average bus ticket costs Euros 4.5

Upvotes: 1

Knows Not Much
Knows Not Much

Reputation: 31576

Do you really need a library for this? you can just use the string replace function like shown here?

http://gordon.koefner.at/blog/coding/replacing-german-umlauts/

Upvotes: 0

Related Questions