scala字符替换_如何替换Scala中的“坏”字符?

scala字符替换

In Scala, programming language, all sorts of special characters are valid. The character set library is quite good and supports almost all characters in Scala programming.

在编程语言Scala中,各种特殊字符均有效。 字符集库非常好,并支持Scala编程中的几乎所有字符。

But some displays do not support the use of all character and while programming this may create an issue as the display will misbehave and the output may get some errors. A display like Radio Pi and some web displays do not support characters like “, ” , ‘ , ’.

但是某些显示器不支持使用所有字符,并且在编程时这可能会引起问题,因为显示器将无法正常工作,并且输出可能会出现一些错误。 诸如Radio Pi之类的显示器和某些Web显示器不支持诸如“,”,“,”之类的字符。

These characters are needed to be handled to get perfect output. For this in Scala, we can create a Scala method that replaces these bad characters with web-friendly once's.

需要处理这些字符以获得完美的输出。 为此,我们可以在Scala中创建一个Scala方法,将其替换为对网络友好的

替换Scala中坏字符的程序 (Program to replace bad characters in Scala)

object MyClass {
    def replacebad(s: String): String = {
        s.replaceAll("“", "\"")
        .replaceAll("”", "\"")
        .replaceAll("‘", "\"")
        .replaceAll("’", "\"")
    }
    
    def main(args: Array[String]) {
        println(replacebad("“"))
        println(replacebad("”"))
        println(replacebad("‘"))
        println(replacebad("’"))
    }
}

Output

输出量

"
"
"
"


翻译自: https://www.includehelp.com/scala/how-to-replace-bad-character-in-scala.aspx

scala字符替换

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值