Help with String.split method

S

sav

I am trying to use the sting split method to do the following, I have
to enter the clients full name and then capture the first name for
correspondence etc . I cant seem to find a suitable way to spearate the
first name from the family name, everytime i run the code i get the
whole name not the first part HELP
FName =
(JOptionPane.showInputDialog("Client Name "));

String[] clientNameArray = FName.split(" ");
for(int i=0;i<clientNameArray.length;i++)
System.out.println(nameArray);
 
E

Eric Sosman

sav said:
I am trying to use the sting split method to do the following, I have
to enter the clients full name and then capture the first name for
correspondence etc . I cant seem to find a suitable way to spearate the
first name from the family name, everytime i run the code i get the
whole name not the first part HELP
FName =
(JOptionPane.showInputDialog("Client Name "));

String[] clientNameArray = FName.split(" ");
for(int i=0;i<clientNameArray.length;i++)
System.out.println(nameArray);


You have put the result of split() in clientNameArray,
but you are printing the contents of nameArray instead.

By the way, automated parsing of people's names is no
easy task and is fraught with peril. "Mary Catherine Smith"
should probably be parsed as "Mary Catherine" + "Smith," not
as "Mary" + "Catherine Smith." Similar concerns apply to
"F. Murray Abraham." In some places it is customary to write
the family name first and the personal name last: the first
person to score a ten in Olympic gymnastics gave her name as
"Comaneci Nadia."

Dear J.,
It's an unpleasant thought, but must be faced: What will
happen to the R. Ewing family if you should die uninsured?
 
S

sav

Thanks for your insight however the reason i am using to print the
results is that i am trying to understand what is being placed into the
array, i am not sure that the split method is doing what i want
 
E

Eric Sosman

sav said:
Thanks for your insight however the reason i am using to print the
results is that i am trying to understand what is being placed into the
array, i am not sure that the split method is doing what i want

(Please quote enough context so that each of your messages
can stand alone.)

In the code fragment you posted earlier, you split() a
string into one array but then printed a different array. It
may be that split() is doing exactly what you expect, but that
you are being misled by the output.

If this is not the case (that is, if the code you posted
is not actually the code that gives you trouble -- Naughty!),
please post a short, complete program that demonstrates your
problem. When you post fragments and paraphrases, you only
force people to guess what your real problem might be.
 
D

DineshOnline

Hi op,

plz trust JAVA to do as it says, this I can say from experience. Also I
believe that if I have done a mistake, however silly that might be, it
is better to admit and correct it as early as possible. e.g. printing
out a different variable ;)

If there is another problem, plz post the original code. Dont worry,
just strip any business URLs, client names frm it.

Y - Peace
 
I

IchBin

sav said:
Thanks for your insight however the reason i am using to print the
results is that i am trying to understand what is being placed into the
array, i am not sure that the split method is doing what i want

It is a lot easier and more rewarding buy using an IDE's interactive
debugger and step through you code. Just either watch objects or inspect
them..

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top