Results 1 to 2 of 2
Thread: Searching for tags in a string
- 02-15-2012, 10:35 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 1
- Rep Power
- 0
Searching for tags in a string
Hi everyone, sorry that my first post here is a question but I've been struggling with this for a while so any help would be greatly appreciated.
I'm working on a project that requires my program to read a question from a text file, and then convert this question into a mathematical equation that can be calculated.
An example from this questions.txt is
As you can see certain areas have been surrounded by parentheses. These parts will need to be identified as mathematical objects and then added to the equation, while the areas outside these tags are stored in another string. The ints will be replaced by randomly generated integers after the question is read through.What is [int] [+] [int]?
In short, after scanning through a question, there should be two strings. One containing a question written in english ("What is 2 + 2?"), and another written as a pure equation(2+2).
My issue is getting the program to recognize these tagged areas and convert them into the equation friendly characters I need. So far it seems the best way to do this is to convert the entire string into a char list and scan through one char at a time, but I'm struggling to keep it simple and I'm reaching a ridiculous amount of nested loops.
If anyone has any ideas it'd really be appreciated. Sorry for such a specific and wordy question, I'm sure it could've been explained better
- 02-15-2012, 11:44 PM #2
Re: Searching for tags in a string
Regular expressions might be just what you need. They allow you to find sequences of characters that follow a specified pattern.
Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
If you start getting into mathematical expressions with nested parentheses and stuff, it will become much more complicated. But a regexp could easily identify a string like "2+2".Get in the habit of using standard Java naming conventions!
Similar Threads
-
Searching for a string in different log files
By nitin kishore in forum Advanced JavaReplies: 6Last Post: 09-14-2011, 09:32 PM -
searching for a word in a string
By Brian-82 in forum New To JavaReplies: 1Last Post: 05-11-2011, 07:19 PM -
Searching for a String within an linked list
By phil128 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 02:18 AM -
[SOLVED] Searching a string in a vector
By coolFrenzi in forum Advanced JavaReplies: 5Last Post: 02-22-2009, 12:53 AM -
Searching In a String Array - Problem
By DillMan in forum New To JavaReplies: 4Last Post: 12-07-2008, 09:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks