[java] Parsing methods??
any good advices on how I can make a really simple parsing engine??
just like searching in a file after a word and read its value:
value = 21
value2 = "a fine string"
value3 = 234.0
Hans-Petter
Well, assuming you have already read in the line to be parsed, then two ways that come to mind to get the value after the '=' are
[edited by - simb on January 24, 2004 2:54:53 AM]
a = "value=21"thenString [] b = a.split( "=", 2); // b[1] is everything after the '='orString b = a.substring( a.indexOf( '=') +1); // b is everything after the '='
[edited by - simb on January 24, 2004 2:54:53 AM]
thanks a lot, didn''t know about those methods! but do java have any methods like atoi (array to int), atof or something? so I can convert the string to the value I want it to be..
Hans-Petter
Hans-Petter
Yep,
Integer.parseInt( "12345")
returns the integer 12345, and there are similar ones for Double, Float, Short, Long, Byte, Boolean and maybe some more (just look in the JavaDocs for those classes for the exact method names)
Integer.parseInt( "12345")
returns the integer 12345, and there are similar ones for Double, Float, Short, Long, Byte, Boolean and maybe some more (just look in the JavaDocs for those classes for the exact method names)
Take a look at java.util.Properties - you can use it to load a button/value-type file as a Hashtable with great ease.
--cfmdobbie
--cfmdobbie
Also, it supports comments.
***
For Java games and Java related resources, go to http://www.javaengines.dk
***
***
For Java games and Java related resources, go to http://www.javaengines.dk
***
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement