| | |
tokenizer
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2005
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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?
Java Syntax (Toggle Plain Text)
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()); } }
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
See the below thread for better understanding of the string tokenizer class
http://www.daniweb.com/techtalkforums/thread26132.html
Another thing is that if you want to split up a string try looking up the java String class api
Richard West
See the below thread for better understanding of the string tokenizer class
http://www.daniweb.com/techtalkforums/thread26132.html
Another thing is that if you want to split up a string try looking up the java String class api
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jun 2005
Posts: 4
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Java's String Tokenizer (Java)
- Help...How do i use the Tokenizer? (Java)
- stream tokenizer (Java)
- String Tokenizer Help (Java)
- Java with String Tokenizer (Java)
Other Threads in the Java Forum
- Previous Thread: object oriented programme help
- Next Thread: Help with a java program home work assignment
Views: 1754 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider detection draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle os plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree windows






