Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想把这个字符串:
"1:a|2:b|3:c"
进入这个:
Map(1 -> "a", 2 -> "b", 3 -> "c")
我有一个可行的程序方法,但似乎应该有一个更实用的方法。
val a = [YOUR STRING] a.split('|').map(_.split(':')).map(a => (a(0) -> a(1))).toMap
val s = "1:a|2:b|3:c" "(\\d+)\\:(\\w+)".r.findAllMatchIn(s).map( m => (m.group(1).toInt -> m.group(2)) ).toMap