How to Break a string into segments containing only text of the string ?

Hi,

I need to break a string with special characters into segments containing only text of the string , not the special chars like ",", " # ", " ","$ " etc.. and then I need to compare the string with database string.

Ex: if string is: " #123, EPIP Phase, White#Field "

it has to be broken into:

Segment 1: 123

Segment 2: EPIP Phase

Segment 3: WhiteField

Can u pls help me with this ?

Thanks,

Sanlearns

[464 byte] By [sanlearnsa] at [2007-10-2 19:32:19]
# 1
It looks like the string contains comma-separated fields, so I'd probably first make sure I got those fields (using String.split() or a StringTokenizer).Then replace all special characters (up to you to define "special") using multiple calls to String.replaceAll().
Herko_ter_Horsta at 2007-7-13 21:19:56 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

Try using StringTokenizer Class.

Eg,

StringTokenizer strT = new StringTokenizer("#123, EPIP Phase, white#Field ", ",");

while(strT.hasMoreTokens())

{

System.out.println(strT.nextToken());

}

this gives the output as,

#123

EPIP Phase

white#Field

You can further do the String manipulations to remove those #.

The second parameter in the StringTokenizer class is the delimiter that is to be used to break the string.

Hope this is useful to you.

Regards,

Prasanna

Prasanna_Ma at 2007-7-13 21:19:56 > top of Java-index,Java Essentials,Java Programming...
# 3
Hey Thanks man !I just read in JDK 1.5 that String Tokenizer class' usage is discouraged.U have String.split(regex) etc..Anyway thanks .Sanjeev
sanlearnsa at 2007-7-13 21:19:56 > top of Java-index,Java Essentials,Java Programming...
# 4
Hey Thanks so much !
sanlearnsa at 2007-7-13 21:19:56 > top of Java-index,Java Essentials,Java Programming...