如何将一个字符串分割成几个字符块?
我有一个来自名为 fld[1].tostring
的数组的字符串。当我尝试拆分此字符串时,它会在 | 上返回 "|R1|R2|R3"
它将它分成每个字符。我做错了什么?
I have a string that came from an array called fld[1].tostring
. When i try and split this string which returns "|R1|R2|R3"
on the | it splits it into each character. what am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
split 方法接受正则表达式。管道字符用于表示 Java 正则表达式中的逻辑 或 。用反斜杠转义字符以分割它。
例如:
The split method accepts regular expressions. The pipe character is used to denote a logical or in Java regular expressions. Escape the character with a backslash to split on it.
For example:
竖线“|”
是特殊字符。和 String.split() 需要正则表达式。尝试转义它并将其视为特殊字符:
Vertical bar "|"
is special character. andString.split()
need a regualar expression.try escaping it and treating it as special char: