【问题标题】:how to split a string which contains of ( \n : , .)如何拆分包含 ( \n : , .) 的字符串
【发布时间】:2017-03-16 06:37:36
【问题描述】:

那么如何在android中拆分这个组合呢?

提前致谢:)`

我正在尝试这样String lines[] = String.split("\\r?\\n", -1); 但是如何一次拆分所有数据

【问题讨论】:

标签: java android


【解决方案1】:

您可以使用 Pattern 进行正则表达式拆分

String fields = "name[Employee Name], employeeno[Employee No], dob[Date of 
Birth], joindate[Date of Joining]";

Pattern pattern = Pattern.compile("\\[.+\\]+?,?\\s*" );

String[] split = pattern.split(fields);

参考:How to split this string using Java Regular Expressions

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    相关资源
    最近更新 更多