English 中文(简体)
我怎么能读大弦的一行一行一行呢?
原标题:How can I read line after line from big String?

认为我有一些大字符串 在以下结构中:

parameter1|parameter2|parameter3|parameter4+""

* 如果参数是某些字符的序列,其长度一般不为人知。

现在想想我的大字符串 持有4行的数据,例如:

parameter1|parameter2|parameter3|parameter4+""
parameter1|parameter2|parameter3|parameter4+""
parameter1|parameter2|parameter3|parameter4+""
parameter1|parameter2|parameter3|parameter4+""

How can I read the first line and then read the second line and so on?
I know that I can use Substring method to get the first line every time easily, however
how can I use Substring(or other methods) to get the next 3 lines of the big string, in order to extract the first line again (which represent the second line of the original big string in practice).
I know that all I need is the index of the last "" (line 4) and I already have the index of current line "".

Should I just use lastIndexOf("")?
If you have any other ideas or even criticism about this way of working, I ll be more than glad to hear about.

谢谢:)

最佳回答

您可以使用 < a href=" "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#split%28java.lang.html#split%28java. string%29" rel="nofollow" >String.split 方法中的 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

问题回答

您可以使用被包在缓冲Reader上的字符串 Reader, 类似 :

BufferedReader r = new BufferedReader(new StringReader("my multiline text..."));
String l = null;
while ((l=r.readLine)!=null) {
 ....
 // each line in "l"
}

http://docs.oracle.com/javase/6/docs/api/java/io/BufferedReader.html#readLine() http://docs.oracle.com/javase/6/docs/api/java/io/StringReader.html

也许,

inputString.split("");

?????

我会使用正则表达式来分隔字符串。 如果您想要在一个字符串数组中的所有单词, 您可以使用 /s( 白空) 作为分隔符模式 。

您可以在以下网页找到信息“http://www.permanization-expressions.info/java.html' rel=“nofollow”>http://www.permanization-expressions.info/java.html





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...