# character

G

gouqizi.lvcha

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
 
V

Victor Bazarov

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

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

Phlip

gouqizi.lvcha said:
I need to process a txt file.

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,353
Latest member
RogerDoger

Latest Threads

Top