Connecting Tech Pros Worldwide Forums | Help | Site Map

# character

gouqizi.lvcha@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
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


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

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...


Phlip
Guest
 
Posts: n/a
#3: Jul 23 '05

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


Closed Thread