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.

java regex split

Thread view: 
Mani - 02 Jun 2006 14:08 GMT
hi,

i want to write a code to split a line containing names followed
cities,emailids,
and store them separately,

in perl,
if the input file contains,
name1 city1 email1 email2 email3
name2 city2 email1 email2 email3

then,i think,

($name,$city,$email)= split /\s+/,$line,3;

can store the names,cities and emails in separate strings.

In java how can this be done?

-Mani
Suresh - 02 Jun 2006 14:14 GMT
> hi,
>
[quoted text clipped - 16 lines]
>
> -Mani

With Java 1.4 and above you could use the split function of the String
class.

String[] tokens="name1 city1 email1 email2 email3".split(" ");
Mani - 02 Jun 2006 17:14 GMT
thanks!

> > hi,
> >
[quoted text clipped - 21 lines]
>
> String[] tokens="name1 city1 email1 email2 email3".split(" ");
Tim Smith - 04 Jun 2006 08:42 GMT
>> ($name,$city,$email)= split /\s+/,$line,3;
>>
>> can store the names,cities and emails in separate strings.
>>
>> In java how can this be done?
...
> With Java 1.4 and above you could use the split function of the String
> class.
>
> String[] tokens="name1 city1 email1 email2 email3".split(" ");

That's not quite the same thing.  Note in the Perl example, he's asked for
it to be split into 3 strings, so he will get these three strings:

   "name1"
   "city1"
   "email1 email2 email3"

Also, probably best to allow for multiple spaces, like in his Perl example,
so what he probably should use is split("\\s+",3).

Signature

--Tim Smith

Jussi Piitulainen - 04 Jun 2006 15:43 GMT
...
>> String[] tokens="name1 city1 email1 email2 email3".split(" ");
>
[quoted text clipped - 8 lines]
> Also, probably best to allow for multiple spaces, like in his Perl
> example, so what he probably should use is split("\\s+",3).

That's hardly realistic, if "name1" stands for a real name: some
people have spaces in their names - you and I, for example - and I
thin some cities do, too.

Just wondering what the real problem is.
Mani - 04 Jun 2006 17:38 GMT
I am not developing any particular application.
I am just learning how certain things in perl can be done using Java.

Just i came across the following link,
http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/

where they have used,
Function to build a hash of hashes
and
Function to build a hash of hashes of hashes

I am just interested and want to know,how it can be done in java.
Thats the intent of my posting...

-Mani

> ...
> >> String[] tokens="name1 city1 email1 email2 email3".split(" ");
[quoted text clipped - 15 lines]
>
> Just wondering what the real problem is.
Jussi Piitulainen - 04 Jun 2006 19:32 GMT
> I am not developing any particular application.
> I am just learning how certain things in perl can be done using Java.
...
> Thats the intent of my posting...

That's ok then.


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.