Connecting Tech Pros Worldwide Help | Site Map

# character

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 02:00 AM
gouqizi.lvcha@gmail.com
Guest
 
Posts: n/a
Default # character

Hi, all

I need to process a txt file.

I want to know how can I ignore the lines beginning with # character.
There maybe some blanks ahead of # character

Rick


  #2  
Old July 23rd, 2005, 02:00 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: # character

<gouqizi.lvcha@gmail.com> wrote...[color=blue]
> I need to process a txt file.
>
> I want to know how can I ignore the lines beginning with # character.
> There maybe some blanks ahead of # character[/color]

So, what's the problem? Skip the blanks and if the first non-blank
character is #, just ignore the rest and go on to the next line...


  #3  
Old July 23rd, 2005, 02:00 AM
Phlip
Guest
 
Posts: n/a
Default Re: # character

gouqizi.lvcha wrote:
[color=blue]
> I need to process a txt file.[/color]

Use a language like Ruby or Python. C++ is for large, hard programs that
lack simpler alternatives.
[color=blue]
> I want to know how can I ignore the lines beginning with # character.
> There maybe some blanks ahead of # character[/color]

Scripting languages, like Ruby or Python, typically come with built-in
regular expression modules. (C++ makes you download and install one of
several rather pernicious Regex alternatives, each with a steep learning
curve.)

So if one line of your file were in the variable 'line'...

if line !~ /^\s*#/ then
process(line)
end

The // delimits a regular expression, and the ^\s*# is pronounced "the
beginning of the line followed by any number of any kind of spacing
characters followed by a hatch #.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.