简体   繁体   中英

Weird Trimming Issue

I have a weird trimming problem here. I have a txt file of about 500, 000 lines of words. But each line starts with 1), 2), 3)... etc. But the problem here is there isn't just one space inbetween 1) and the word, there are often multiple spaces, and sometimes even a space before the 1), like, right at the start of the line.

I'm not sure how I can just remove all of that stuff that starts before the actual word. But I am 100% sure that there is always a space right before the first word.

How can I go about trimming it this way?

Any help is appreciated.

Thank you!

Example:

textfile.txt:

1) Awesome stuff here 
2) wow 
3) ldfjg ldfk gjldfkg jldfk gjldfkg this line is to be kept too 
4   ) and this too! this is great content 
5 ) gotta love content 
6) content is ok..
   7     ) this is a little odd.

The simplest function is TrimStart :

 string cleaned = line.TrimStart(' ',')','1','2','3','4','5','6','7','8','9','0');

it matches all your samples and is easy to adapt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM