-2

I want to move all lines from String apa1; to String apa2; until we find the first blank line.


apa1 can look like this:

texttest: text test
test text test text

Lorem ipsum dolor sit
amet, consectetur 
adipiscing: elit. 
Curabitur dolor lectus, 
cursus ac placerat vitae, 
volutpat sit: amet lacus.

I want apa1 to look like this:

Lorem ipsum dolor sit
amet, consectetur 
adipiscing: elit. 
Curabitur dolor lectus, 
cursus ac placerat vitae, 
volutpat sit: amet lacus.

And apa2 to look like this:

texttest: text test
test text test text

How do you solve this problem?

4

1 回答 1

1

它应该是这样的。只需继续将第一个字符串复制到第二个字符串,直到遇到空行

String apa1 = @"texttest: text test
                test text test text

                Lorem ipsum dolor sit
                amet, consectetur 
                adipiscing: elit. 
                Curabitur dolor lectus, 
                cursus ac placerat vitae, 
                volutpat sit: amet lacus.";
String apa2 = string.Empty;

String tmp = String.Copy(apa1);
StringReader strReader = new StringReader(tmp );
String line = strReader.ReadLine();

while(!string.IsNullOrEmpty(line))
{
    apa2 += line;
    line = strReader.ReadLine();
}

apa1 = strReader.ReadToEnd();
于 2013-04-16T00:31:39.153 回答