Will this ID always be in that format, or will the comma and such be in different places?
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
You could do this if it has a comma,dash,space, and nothing else...Although I'm not sure why you want to go down such a rocky road..Can't you just store the original id in a string?
import java.util.*;
class TestTokenizer
{
public static void main(String[] args)
{
ArrayList alTokens = new ArrayList();
String id = "SD125,SD478-SD478 SD147";
System.out.println("Original ---> " + id);
int commaIndex = id.indexOf(",");
int dashIndex = id.indexOf("-");
int spaceIndex = id.indexOf(" ");
StringTokenizer st = new StringTokenizer(id,",- ");
while (st.hasMoreTokens())
{
alTokens.add(st.nextToken());
}
StringBuffer sb = new StringBuffer();
for (int i=0; i<alTokens.size(); i++)
{
System.out.println(alTokens.get(i).toString());
sb.append(alTokens.get(i).toString());
}
sb.insert(commaIndex,",");
sb.insert(dashIndex,"-");
sb.insert(spaceIndex," ");
System.out.println("Back to original order---> " + sb.toString());
}
}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10