On Oct 31, 2008, at 6:36 PM, Eric de La Rochette wrote:
Hello there,
I have a string containing data lines, comment lines (the ones that
start with a "#") or empty lines. And, when a valid data line starts
with a "#", it is escaped like this "##"
I need to clean this string in order to keep only the data lines. As
I find RegEx a good way to do it, I started to code the removal of
comment lines like this ( r is Dimed as RegEx, theRawData &
theCleanData are strings ):
r.SearchPattern = "^#[^#].*\n*" // I also tried "^#[^#].*[\n\r]*"
r.ReplacementPattern = ""
r.Options.ReplaceAllMatches = True
theCleanData = r.Replace( theRawData )
So, this code removes the content of the comment line, but not the
line itself. I thought that as the '\n*' is part of the search, it
should have been replaced to...
As I need to also remove the empty lines, it shouldn't be such an
issue. Unfortunately, I have no idea at all on how should look a
search pattern that would find the empty lines... :-(
Any Advice ?
I'm not sure that RegEx is not the way to do it. But if you must,
r.SearchPattern = "#[^#]*\n"
will work for A Mac app reading text with Mac line endings. My
testing in the course of drafting this reply suggests that getting
this to work cross-platform is rather tricky.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|