Monday, 15 August 2011

How to edit a number of text files in a folder in C#? -


I have several text files in the folder (1800 files), all of which are the same formatting, they start like this: < / P>

"station ABDEHGAH_ Lat = 30 27 lang = 51 2

1998 1 35050

1998 2 27800

1998 3 39500

1998 4 0 "

I like to edit this first line of all of them:" Abedgah 30.27 51.2 "

What should I do?

You just need to search and replace _Lat = " With " and replace long = with " " in all the files. It will include three steps:

  1. You have to loop through all the files in the folder.

  2. Read the contents of each file For each file, find _Lat = and long = and save it to < Code> "Change with,

  3. " . Use the method to note that you can only use String.Replace when _Lat = and long = are consistent in all files I mean if it is something like station ABDEHGAH_ kick = 30 27 lang = 51 2 in another file and in the second it is something like , station ABDEHGAH_ Lat = 30 27 lang = 51 2 < / Code>. Note the space if it is not compatible so you have to use the pattern to see and replace them.

No comments:

Post a Comment