regex - c# split text file by changing the line number -
i'm trying split text file line numbers, example, if have text file like:
1 ljhgk uygk uygghl \r\n 1 ljhg kjhg kjhg kjh gkj \r\n 1 kjhl kjhl kjhlkjhkjhlkjhlkjhl \r\n 2 ljkih lkjhl kjhlkjhlkjhlkjhl \r\n 2 lkjh lkjh lkjhljkhl \r\n 3 asdfghjkl \r\n 3 qweryuiop \r\n i want split 3 parts (1,2,3), how can this? size of text large (~20,000,000 characters) , need efficient way (like regex).
another idea, can use linq groups you're after, splitting each first word. note take each first word, make sure have numbers there. using split/join antipattern, seems work nice here.
var lines = line in s.split("\r\n".tochararray(), stringsplitoptions.removeemptyentries) let linenumber = line.split(" ".tochararray(), 2).firstordefault() group line linenumber g select string.join("\n", g); notes:
groupbygurenteed return lines in order appeared.- if block appears more once (e.g.
"1 1 2 2 3 3 1"), blocks same number merged.
Comments
Post a Comment