Click to See Complete Forum and Search --> : Parsing, or Splitting.. or manybe something else?


MadamZuZu
05-09-2006, 04:11 PM
hello.
i'm very new to java and i have this problem.

I need to input a phone number and then split it into different numbers.
so, my dilema is how to do it.

should i take the input as Integer, and then try to split it into separate numbers?

or is there a way (like in C++ pointers) to input the integer into an int array right away, from the command line?

i don't know if im being very confusing... here's an example

lets say the number is 301-221-1083 i would like to have an array of
3
0
1
2
2
1
1
0
8
3

......... you know what i mean?

Thanks for your help!!! :)

Tanya

Khalid Ali
05-09-2006, 06:18 PM
u get the input as a string.
then go thru the string using String.charAt(n) function,
and u can put the results to where ever u want

MadamZuZu
05-10-2006, 04:59 PM
that worked, thanks
now i have another very stupid question.
how do i exit from a console application?
this is my code


if(PhoneNumber.toUpperCase() == "QUIT" || PhoneNumber.toUpperCase() == "EXIT")
{
System.out.println("Good Bye");
System.exit(1);
}
else
{
System.out.println(PhoneNumber.toUpperCase());
}


but it's not working, i tryied doig system.exit(0) as well as exit(1)

what do i do? it doesnt seem to quit.... :(

Khalid Ali
05-10-2006, 05:05 PM
what do u mean? java will just exit the java program, but you will still be in the dos window. I hope thats what u were asking

MadamZuZu
05-11-2006, 08:58 AM
for example... if i put an output line after my exit() command, it will still display it.... but it shouldn't, should it?

sridhar_423
05-11-2006, 09:41 AM
String phone="1212-212-12-12";
char[] phomeArr = null;
phomeArr = (phone.replaceAll("-","")).toCharArray();


exit will terminate the execution.
my advice to you is to download the java api. there are so many methods and it is impossible to remember all of them.

Khalid Ali
05-11-2006, 02:17 PM
as I mentioned before, if you are using a GUI then exit(0); should close the program, if you are using dos command window to run the program then your will quit but u will still be in the dos command window after that program exits...
So you have to make it clear here for us which one of the above is u are trying to exit
out of....