I need a c# program which can split strings and copy some particular informations into another file.
I’ve a text file like this:
BRIDGE.V2014R6I1.SOFT
icem.V4R12I2.SOFT
mygale.V4R1I1.SOFT,patch01_MAJ_APL.exe
photoshop.V2014R10I1.SOFT
rhino.V5R0I1.SOFT,patch01_Update_Files.exe
TSFX.V2R3I2.SOFT,patch01_corrections.exe,patch02_clock.exe,patch03_correction_tri_date.exe,patch04_gestion_chemins_unc.exe
and I need only some of these information into another file as below :
BRIDGE,SOFT
ICEM,SOFT
MYGALE,SOFT
PHOTOSHOP,SOFT
any helps pls 🙂
2
Answers
I would split the string and create a new file with parts of the array you got from the split.
You can split a string with eg.
Split(".");
And then e.g. create a new string
stringname = splitstring[0] + "," + splitstring[2]
That would add the first and third part back together.
That would apply to your first line.
As I don’t know, wether your text file is always like that, I can only provide a specific answer. First of all you have to, as ThatsEli pointed out, split the string at the point:
Now it seems as though your second (zero based index) item has the irrelevant information with a comma splitted from the relevant. So all you have to do is to build together the zeroth and the second, while the second only has the first part before the comma:
However, you seem to want your result in uppercase:
But actually this only works as long as you have a perfect input file – otherwise you have to check, wether it actually has that many items or you’ll get an IndexOutOfRange exception.
Actually I’m not sure wether you know how to read/write from/to a file, so I’ll provide examples on this as well.
Read
Write