[英]Divide string into two parts based on separator in Scala
input: 输入:
myString = ""FILTER=(ID=123,Description=456)"" myString =“”过滤器=(ID = 123,描述= 456)“”
output: 输出:
FILTER, (ID=123,Description=456) 过滤器,(ID = 123,说明= 456)
basically divide the string into two parts How can i achieve this ? 基本上将字符串分为两部分,我该如何实现?
Want something equivalent to str.partition(sep) as in python 想要与python中的str.partition(sep)等效的东西
You want split
with a limit
parameter (but you don't get the separator as an element as in the Python partition
) 您想使用
limit
参数进行split
(但不要像Python partition
那样将分隔符作为元素使用)
val myString = "FILTER=(ID=123,Description=456)"
myString.split("=", 2)
//> res0: Array[String] = Array(FILTER, (ID=123,Description=456))
The span
-method could also be helpful for you span
-method也可能对您有帮助
val myString = "FILTER=(ID=123,Description=456)"
//myString: String = FILTER=(ID=123,Description=456)
myString.span(_!='=')
//res9: (String, String) = (FILTER,=(ID=123,Description=456))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.