realbasic-nug
[Top] [All Lists]

Re: Removing comments or empty lines in a string

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Removing comments or empty lines in a string
From: Charles Yeomans <charles@declareSub.com>
Date: Fri, 31 Oct 2008 19:12:43 -0400
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <7A56BED8-B975-415B-BD9D-7395F9BC3DF8@edlr.fr>
References: <7A56BED8-B975-415B-BD9D-7395F9BC3DF8@edlr.fr>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

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>


<Prev in Thread] Current Thread [Next in Thread>