1
C# merge lines of strings into groups with specified word
source link: https://www.codeproject.com/Questions/5322721/Csharp-merge-lines-of-strings-into-groups-of-3-at
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
See more:
I have a text file which look like this:
Copy Code
Name:John Age:18 Info:(text message) Name:May Age:17 Info:(text message) Name:Jane Age:17 Info:(text message)
I want to make Name, Age, Hobby in 1 group. Thus, I make the string like this by the code below,
Copy Code
Name:John,Age:18,Hobby:(text message) Name:May,Age:17,Hobby:(text message) Name:Jane,Age:17,Hobby:(text message)
However, the sequence will get disturb if the 'info' part have a long message and go into second line.
Copy Code
<pre>Name:John Age:18 Info:(text message) Name:May Age:17 Info:(text................................ ....................................message) Name:Jane Age:17 Info:(text message)
Any suggestion if I want to group them with specified word(Name, Age, Info)? So that it would not get disturb when the text message is long.
What I have tried:
Copy Code
string[] lines = myInputString.Split(new[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Count(); i = i + 3) { var res = string.Join(",", lines.Skip(i).Take(3)); }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK