i need to separate a string and identify by which delimeter i separated becouse at the end im going to unate again how do i do that???
i have this code
ArrayList alTokens = new ArrayList();
String id="Actualiza por Datos SD125,SD908-SD478 SD147 \n *,*,*,*,*,*,* \n 11/04/2004 14723.0125";
System.out.println("Original ---> \n " + 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---> \n " + sb.toString());
it separetes and when i put it together again i get
Back to original order--->
Actualiza porDatosSD125SD9,08SD4-78SD147
*******
11/04/200414723.0125
THE TROUBLE COMES WHEN I WANT TO GET TOGETHER THE STRING BECOUSE I DONT KNOW BY WHAT DELIMITER I SEPARATED THE STRING AND I DIDNT GET THE COMMA IN THE RIGTH PLACE I DONT KNOW WHY
i have this code
ArrayList alTokens = new ArrayList();
String id="Actualiza por Datos SD125,SD908-SD478 SD147 \n *,*,*,*,*,*,* \n 11/04/2004 14723.0125";
System.out.println("Original ---> \n " + 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---> \n " + sb.toString());
it separetes and when i put it together again i get
Back to original order--->
Actualiza porDatosSD125SD9,08SD4-78SD147
*******
11/04/200414723.0125
THE TROUBLE COMES WHEN I WANT TO GET TOGETHER THE STRING BECOUSE I DONT KNOW BY WHAT DELIMITER I SEPARATED THE STRING AND I DIDNT GET THE COMMA IN THE RIGTH PLACE I DONT KNOW WHY