Formatting a string

Hi,

I am trying to format a string e.g.

"ou=Applications"

to just extract the "Application" part of the string?

I think you can use the StringTokenizer class and "=" as a delimeter, but I tried that and it did not work for me!

Can someone please tell me how to do this and give me an example piece of code if possible?

Thanks.

[370 byte] By [patelk9a] at [2007-9-29 16:09:18]
# 1

StringTokenizer should work on this...

String yourString = new String("key=value");

String result;

StringTokenizer st = new StringTokenizer(yourString, "=");

if(st.countTokens() == 2) {

st.nextToken();

result = st.nextToken();

}

else {

System.out.println("illegal formatted string...");

}

not that nice - but it should work :)

Thofa at 2007-7-15 14:20:45 > top of Java-index,Archived Forums,Portability & Platform Independence [Archive]...
# 2

Or, better yet, just use the String split method:

String ldapEntry = "ou=Applications";

String [] tokens = ldapEntry.split("=");

System.out.println(tokens[1]); // prints out "Applications"

Just one line of code does it. - MOD

duffymoa at 2007-7-15 14:20:45 > top of Java-index,Archived Forums,Portability & Platform Independence [Archive]...