Scala 日常操作备忘

2017-09-30  本文已影响8人  一条湫刀鱼
scala> val str = "崔*华"
str: String = 崔*华

scala> val strs = str.split("")
strs: Array[String] = Array(崔, *, 华)

scala> val TAKE_ZH = """[\x{4e00}-\x{9fa5}]""".r 
TAKE_ZH: scala.util.matching.Regex = [\x{4e00}-\x{9fa5}]

scala> import scala.util.matching.Regex
import scala.util.matching.Regex

scala> TAKE_ZH findAllIn(str)
res0: scala.util.matching.Regex.MatchIterator = non-empty iterator

scala> TAKE_ZH findAllIn(str).mkstring
<console>:15: error: value mkstring is not a member of String
       TAKE_ZH findAllIn(str).mkstring
                              ^

scala> (TAKE_ZH findAllIn(str)).mkstring
<console>:15: error: value mkstring is not a member of scala.util.matching.Regex.MatchIterator
       (TAKE_ZH findAllIn(str)).mkstring
                                ^

scala> (TAKE_ZH findAllIn(str)).mkString
res3: String = 崔华
上一篇下一篇

猜你喜欢

热点阅读