[SOLVED] recieving an int from a nonmumeric string
Hi,
i've tried to do the above in a numerous amount of ways; splitting, parsing etc etc etc..
here goes:
int mut = Group.numOfGames();
String[] matches = new String[mut];
for (int i = 0; i < mut; i++){
int t = i+1;
matches[i] = t + " " + Group.player1.get(i) + " vs " + Group.player2.get(i);
}
String matchnr = (String)JOptionPane.showInputDialog(null, "Match nr", "Result",
JOptionPane.QUESTION_MESSAGE, null,
matches, matches[0]);
String[] options = { "1-0", "0-1" };
int index = JOptionPane.showOptionDialog(null, "Matchresultat", "Result",
0, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
what i want to do is to get the variable t (which is actually set in matchnr), a question field pops up and you get to choose match number (with player1 vs player2 visible) and string matchnr gets set by that choice. umm, hope my explanation is not to mixed up.
please help me with this, any help will do.
regards
Ulfar.
read up on regular expressions
Quote:
Originally Posted by
Ulfar
so basically i just call this method and it will pick out any numeric values?
That is an oversimplification, study eranga's link - but get ready for a long-haul study. Regular expressions do the work you need but are not easy to use at first. They get easier - it is only a matter of how long it takes. The best tutorial I have found is in the javadocs for Pattern class. That's what I used to write this.
edit: Here, try this:
Code:
String inputValue = JOptionPane.showInputDialog("Please type in \"1-0\" or \"0-1\"");//
Then run the above on it, you can do parseInt() to get an actual numeric as the computer understands it.