Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Help with String.split method

Thread view: 
sav - 11 Jun 2006 18:45 GMT
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[i]);
Eric Sosman - 11 Jun 2006 19:36 GMT
> 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
[quoted text clipped - 7 lines]
>                 for(int i=0;i<clientNameArray.length;i++)
>                     System.out.println(nameArray[i]);

    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?

Signature

Eric Sosman
esosman@acm-dot-org.invalid

sav - 11 Jun 2006 20:55 GMT
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
Eric Sosman - 11 Jun 2006 22:30 GMT
> 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.

Signature

Eric Sosman
esosman@acm-dot-org.invalid

DineshOnline@gmail.com - 12 Jun 2006 06:51 GMT
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
IchBin - 12 Jun 2006 07:25 GMT
> 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-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.