• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stacks and ques

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have written a progam wich matches parentheses. How would i ammend this so that the program ignore anything that is written between the speech marks.
for example if someone types in (a+6)*56-"57(+8)"=
it will ignor the () inside the speach marks.
Here is my progam which matchs parentheses. But what changes do i need to make
Thanks
[ edited to format code and to help preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 26, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hope that helps,
Tom Blough
[ edited to close the code tag -ds ]
[ March 26, 2004: Message edited by: Dirk Schreckmann ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, mabolza!
Have you considered using a regular expressions API? If you're not already familiar with regex's, this might be a very good opportunity to begin to learn about them. They can be very handy when processing text.
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if you don't want to incur the overhead of regex, then you can simply use a StringTokenizer:

Then you can call nextToken(), nextToken(), nextToken(). Every time you encounter a "(", you add one to a variable x, every time you encounter a ")", subtract one. If you wind up with 0, then you have an equal number. If have negative number, you have more ")", positive you have more "(".
sev
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parsers often keep track of where they are in the input sytnax with "state" information. You might get by with:

See if that kind of logic holds up to your input data. Things get trickier if you have escape characters, like \" is allowed inside the quoted string and does not end the quoted string.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic