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