rnicholus
asked on
String.split(String regex, int limit) question
Take the string:
2000 S 900 W
Is there a way in which I could use the split method on this string such that the contents of the String array are:
2000 S
900 W
As far as I know, the spilt method cannot return delimiters. So, if this is true, can someone tell me how I can do this efficiently?
2000 S 900 W
Is there a way in which I could use the split method on this string such that the contents of the String array are:
2000 S
900 W
As far as I know, the spilt method cannot return delimiters. So, if this is true, can someone tell me how I can do this efficiently?
ASKER
Actually, there aren't always 4 tokens. Sometime there may be 6, sometime 2. Oh well.
Before you accept anything, let me see if I can produce a solution for that instead...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
After talking with my data engineer, I just realized that these are street suffixes, and I can't use them anyway in my situation. I will give you credit for your work, though. I apologize for taking up your time.
lol - Okay then. :-)
If there's always 4 tokens, then you can do something like this:
String str = "2000 S 900 W";
StringTokenizer st1 = new StringTokenizer( str, " " );
String token1 = st1.nextToken();
token1 += st1.nextToken();
String token2 = st1.nextToken();
token2 += st1.nextToken();