分解页面上的文字

时间:2014-02-27 07:25:16

标签: java android

我有一个字符串

String str = "line1"+"\n" +
               "line2"+"\n" +
               "line3"+"\n" +
               "line4"+"\n" +
               "line5"+"\n" +
               "line6"+"\n" +
               "line7"+"\n" +
               "line8"+"\n" +
               "line9"+"\n" +
               "line10"+"\n" +
               "line11"+"\n" +
               "line12"+"\n" +
               "line13"+"\n" +
               "line14"+"\n" +
               "line15"+"\n" +
               "line16"+"\n" +
               "line17"+"\n";

我想摆脱一串字符串

String str1 =      "line1"+"\n" +
                   "line2"+"\n" +
                   "line3"+"\n" +
                   "line4"+"\n";

String str2 =      "line5"+"\n" +
                   "line6"+"\n" +
                   "line7"+"\n" +
                   "line8"+"\n";

String str3 =      "line9"+"\n" +
                   "line10"+"\n" +
                   "line11"+"\n" +
                   "line12"+"\n";

String str4 =      "line13"+"\n" +
                   "line14"+"\n" +
                   "line15"+"\n" +
                   "line16"+"\n";

String str5 =       "line17"+"\n";

如果我这样做

 String[] str1 = str.split("\n");

我得到一个字符串数组,其中只有一行,我需要一些 而不是字符串我将有一个文件,我打算从中读取文本

1 个答案:

答案 0 :(得分:0)

要分割具有特定格式的字符串,您需要指定正则表达式 所以在你的情况下,正则表达式将是(“\ r \ n”)

Look Here