Results 1 to 2 of 2
Thread: Searching for tags in a string
- 02-15-2012, 11:35 PM #1Member
- Join Date
- Feb 2012
- Rep Power
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
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-16-2012, 12:44 AM #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!
- By nitin kishore in forum Advanced JavaReplies: 6Last Post: 09-14-2011, 09:32 PM
- By Brian-82 in forum New To JavaReplies: 1Last Post: 05-11-2011, 07:19 PM
- By phil128 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 02:18 AM
- By coolFrenzi in forum Advanced JavaReplies: 5Last Post: 02-22-2009, 01:53 AM
- By DillMan in forum New To JavaReplies: 4Last Post: 12-07-2008, 10:12 PM