Scala:处理String中的特殊编码字符

时间:2018-04-19 00:18:36

标签: scala

我的字符串包含许多变音字符# Create a global Event shutdown_event = tornado.locks.Event() def shutdown(): # Same as in the question, but instead of `io_loop.stop()`: shutdown_event.set() @gen.coroutine def main(): # Use a WaitIterator to exit when either the queue # is done or shutdown is triggered. wait_iter = gen.WaitIterator(q.join(), shutdown_event.wait()) # In this case we just want to wait for the first one; we don't # need to actually iterate over the WaitIterator. yield wait_iter.next() 和欧元(ä,ö,ü)符号。是否有任何库或现有方法在Scala中将它们分别转换为(€)(a,o,u)

我知道python中的类似库可以完成这项工作,但似乎无法在scala中找到它。

请考虑以下示例:Euro(or its equivalent)

我希望转换为类似这样或类似的内容:val String="Köln and München are great cities. The average bus ticket costs €4.5"

2 个答案:

答案 0 :(得分:1)

您可以使用您需要应用的任何规则来构建自己的翻译器。

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

答案 1 :(得分:0)

你真的需要一个图书馆吗?你可以使用这里显示的字符串替换函数吗?

documentation