c# Replace?
I have a bunch of text files that get loaded into strings at the start of the program. These strings will have custom color codes like ect. But I need to replace those with the xterm color codes. Say is '\e[38;5;196m' how would I do this?
Sam HobbsPosted May 22, 2011, 3:49 PM
I have written programs that convert data such as what you need to process. I wrote a program that reads the manufacturing instructions for building aircraft. I don't know what type of aircraft; it was classified. The manufacturing instructions that were converted were instructions intended only for people and had information such as the tools and material required for a manufacturing operation. There were many operations; everything required to make an entire aircraft. I assume Vulpes and other developer here have also written programs to parse text such as what you need. I would help more if I understood better what you need to do but your requirements are still quite vague.
It is extremely common for programmers to use the term "one-time conversion". It means one time; that the conversion is done once and only once and never ever done again.
So do you not understand "Does any of your programs read the old (current) format?"? What part do you not understand? If this data has never, ever been read by any program that you have source code for, then just say so.
MastermosleyPosted May 22, 2011, 2:30 PM
VulpesPosted May 22, 2011, 6:36 AM
Sam HobbsPosted May 22, 2011, 4:03 AM
Does any of your programs read the old (current) format? When I say "your" I mean anywhere in your organization.
MastermosleyPosted May 22, 2011, 3:43 AM
Sam HobbsPosted May 22, 2011, 1:55 AM
If the files remain the same, then you still must read the old format. You just add a post-load conversion, and the way to do that depends what you data looks like after it is loaded.
If you need to do a one-time conversion of the data, then just use the code that you already have to load the data, then do a conversion and write that out.
MastermosleyPosted May 21, 2011, 11:26 PM
MastermosleyPosted May 21, 2011, 11:12 PM
Posted May 21, 2011, 10:58 PM
Which one will be faster /best ?
String.Replace() or RegEx.replace()
Mahesh ChandPosted May 21, 2011, 10:47 PM
http://www.c-sharpcorner.com/UploadFile/mahesh/2883/
Posted May 21, 2011, 10:36 PM
using System.IO;
using System.Text.RegularExpressions;
static public void ReplaceInFile( string filePath, string searchText, string replaceText )
{
StreamReader reader = new StreamReader( filePath );
string content = reader.ReadToEnd();
reader.Close();
content = Regex.Replace( content, searchText, replaceText );
StreamWriter writer = new StreamWriter( filePath );
writer.Write( content );
writer.Close();
}
Hope this helps you.