Connecting Tech Pros Worldwide Help | Site Map

# character

  #1  
Old July 23rd, 2005, 03:00 AM
gouqizi.lvcha@gmail.com
Guest
 
Posts: n/a
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, 03:00 AM
Victor Bazarov
Guest
 
Posts: n/a

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, 03:00 AM
Phlip
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
character sets Paul W answers 10 September 16th, 2008 07:55 AM
Character Classes and Special Characters KevinADC insights 3 February 4th, 2008 08:26 AM
wide character (unicode) and multi-byte character =?Utf-8?B?R2Vvcmdl?= answers 17 May 9th, 2007 09:35 AM
how to initial and print the unicode character? wizardyhnr answers 15 July 7th, 2006 04:45 AM
printing % with printf(), use of \ (escape) character teachtiro@yahoo.com answers 7 November 14th, 2005 06:59 PM