Saturday, March 31, 2012

Trim fields in Text File

Hi

I have a text file with 116 fields separated by commas. How would I open the text file and trim all white spaces from each field and then close file?

Thanks

You can Use String.Split function to get array of all string with whitespace than trim that string and Use String.Join function to get comma seperated string

than store it in file


Even simpler would be to run a regex replace on your textfile after readingit.

Regex.Replace(strInput, "\s+", " ")

0 comments:

Post a Comment