O
Open Galaxy
Guest
Hello my friend:
I am writing a Text file to CSV but I want to remove all embedded commas:
For example: I want to change this: "Daft Punk, is great" to "Daft Punk - is great"
I do not know must about Regex. But is there a Regex that I can add to my code below to replace any comma that is between two letters?
More Examples:
"A B C D, E F G" or "A B C D,E F G" would turn to this: "A B C D - E F G"
Here is my code:
static void TextToCSV(string s, TextWriter writer)
{
foreach (var line in s.Replace(", ", "").Split(new string[] { Environment.NewLine}, StringSplitOptions.None))
{
foreach (var t in line)
{
writer.Write(t);
}
writer.WriteLine();
}
writer.Flush();
}
static void Main(string[] args)
{
TextReader reader = new StreamReader(@"C:\myfolder\sample.txt");
string a = reader.ReadToEnd();
reader.Close();
FileStream aFile = new FileStream(@"C:\myfolder\sample.csv", FileMode.Create);
TextToCSV(a, new StreamWriter(aFile));
aFile.Close();
}
Thanks everyone!
Continue reading...
I am writing a Text file to CSV but I want to remove all embedded commas:
For example: I want to change this: "Daft Punk, is great" to "Daft Punk - is great"
I do not know must about Regex. But is there a Regex that I can add to my code below to replace any comma that is between two letters?
More Examples:
"A B C D, E F G" or "A B C D,E F G" would turn to this: "A B C D - E F G"
Here is my code:
static void TextToCSV(string s, TextWriter writer)
{
foreach (var line in s.Replace(", ", "").Split(new string[] { Environment.NewLine}, StringSplitOptions.None))
{
foreach (var t in line)
{
writer.Write(t);
}
writer.WriteLine();
}
writer.Flush();
}
static void Main(string[] args)
{
TextReader reader = new StreamReader(@"C:\myfolder\sample.txt");
string a = reader.ReadToEnd();
reader.Close();
FileStream aFile = new FileStream(@"C:\myfolder\sample.csv", FileMode.Create);
TextToCSV(a, new StreamWriter(aFile));
aFile.Close();
}
Thanks everyone!
Continue reading...