i have this string SD125,SD478-SD478 SD147
i need to separate,but i need to know which delimeter i use becouse i did this

StringTokenizer sd = new StringTokenizer(fileStringSD, ", -");

          while (sd.hasMoreTokens())
           {
               String cad = sd.nextToken();                 
                system.out.printl (cad);
           }

it separetes and i get

SD125
SD478
SDSD147

THE TROUBLE COMES WHEN I WANT TO GET TOGETHER THE STRING BECOUSE I DONT KNOW BY WHAT DELIMITER I SEPARATED THE STRING

Edited 3 Years Ago by pyTony: fixed formating

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());
	}
}

it could be anywhere so i need a code where no matters where the comma is

THANKS FOR THE HELP, I PROVED YOUR CODE THE TROUBLR HERE IS THAT NOT ALWAYS I HAVE THAT STRING I have a file like this

ExchangeNumbers
SD00171-SD00125,SD00258 SD00015
*,*,*,*,*,*
11/04/2004 14723.0125

What i need is to separate everything becouse i need to exchange the SD### STRING for another that i have in anoteher file thats why i need to know exactly by which symbol i separate the sting to at the end of the exchange put it again like this:

ExchangeNumbers
SF124-SF758,SF359 SF142
*,*,*,*,*,*
11/04/2004 14723.0125

This article has been dead for over six months. Start a new discussion instead.