用|拆分字符串分隔

时间:2018-05-07 14:36:14

标签: java string scala apache-spark

Abaqus License Manager checked out the following license(s): "cae" release 6.13 from zhouhongwei <1023 out of 1024 licenses remain available>. WindowsError: exception: access violation reading 0X000007FF080BA0A0 File "t.py" ,line 13, in <module> flib.rand_nucle<data.ctypes.data,n3,nl,n2> Abaqus Error: cae exited with an error ===&gt;仅显示"abc|xyz|".split("\\|").foreach(println)abc

xyx ===&gt;长度应为3,但显示为2。

当我使用竖线分隔的字符串拆分时,最后一列的值为空。拆分功能忽略了最后一个值。

1 个答案:

答案 0 :(得分:3)

您应该使用limit split函数作为-1,这将为您提供预期的

"abc|xyz|".split("\\|", -1).foreach(println)

这导致输出为abcxyx''

println("abc|xyz|".split("\\|", -1).length)

这导致长度为3