I am working on porting code from JAVA to C #, and part of the JAVA code uses a tokenizer, but I understand that the resulting array from stringtokenizer in Java will also have delimiters (in this case +, -, /, *, (,)) as tokens. I tried using the C # Split () function, but it seems to eliminate the delimiters itself. In the end, it will parse the string and run it as a calculation. I did a lot of research and did not find references on this topic.
Does anyone know how to get the actual delimiters in the order in which they were found in the split array?
Code for tokens:
public CalcLexer(String s) { char[] seps = {'\t','\n','\r','+','-','*','/','(',')'}; tokens = s.Split(seps); advance(); }
Testing:
static void Main(string[] args) { CalcLexer myCalc = new CalcLexer("24+3"); Console.ReadLine(); }
"24 + 3" will lead to the following conclusion: "24", "3" I am looking for a way out of "24", "+", "3"
In the nature of full disclosure, this project is part of the class assignment and uses the following complete source code:
http://www.webber-labs.com/mpl/source%20code/Chapter%20Seventeen/CalcParser.java.txt http://www.webber-labs.com/mpl/source%20code/Chapter%20Seventeen/CalcLexer .java.txt
c # stringtokenizer
Ipster Jul 15 '09 at 21:52 2009-07-15 21:52
source share