Questions tagged [stringtokenizer]

StringTokenizer is a Java class that breaks a string into tokens.

This tag is used for questions about or involving the StringTokenizer class in Java, which is used to break a single string into multiple, individual "tokens".

StringTokenizer is an old class, called the "legacy class" in documentation, suggesting to use String.split instead. However as of 1.7, it is not deprecated. Another class with similar but more advanced functionality is .

Questions tagged should also be tagged .

Useful links:

627 questions
8
votes
8 answers

Java StringTokenizer with empty tokens

I have a string that looks some thing like - 56,0,76,0,93,,,,,,,1230. I use a StringTokenizer to split this by ','. However, it seems that this is skipping from 93 straight to 1230. Is there a way to make it return six empty strings before it moves…
Rohit Pandey
  • 2,443
  • 7
  • 31
  • 54
8
votes
3 answers

how does the String.Split method determine separator precedence when passed multiple multi-character separators?

If you have this code: "......".Split(new String[]{"...", ".."}, StringSplitOptions.None); The resulting array elements are: 1. "" 2. "" 3. "" Now if you reverse the order of the separators, "......".Split(new String[]{"..", "..."},…
John Smith
  • 4,416
  • 7
  • 41
  • 56
7
votes
2 answers

Reading data from RandomAccessFile producing incorrect results - Java

I have a text file with 42 lines. Each line has more than 22,000 numbers separated by comma. I wanted to extract certain numbers from each line, and I have an int array with a length of 1000 containing a 1,000 numbers that I need from each of…
6
votes
4 answers

Parsing Data from CSV to Array in Java

I'm trying to import a CSV file into an array that I can use within a Java program. The CSV file has successfully imported itself and the output appears on Terminal but it throws the error: Exception in thread "main"…
Roger Chen
  • 93
  • 1
  • 1
  • 6
6
votes
6 answers

Capitalize first word of a sentence in a string with multiple sentences

eg: String s="this is a.line is .over " should come out as "This is a.Line is.Over" I thought of using string tokenizer twice -first split using"." -second split using " " to get the first word -then change charAt[0].toUpper now i'm not sure…
kshitij
  • 111
  • 2
  • 2
  • 9
5
votes
9 answers

Replicating String.split with StringTokenizer

Encouraged by this, and the fact I have billions of string to parse, I tried to modify my code to accept StringTokenizer instead of String[] The only thing left between me and getting that delicious x2 performance boost is the fact that when you're…
Dani
  • 4,267
  • 4
  • 29
  • 37
5
votes
6 answers

Tokenizing strings using regular expression in Javascript

Suppose I've a long string containing newlines and tabs as: var x = "This is a long string.\n\t This is another one on next line."; So how can we split this string into tokens, using regular expression? I don't want to use .split(' ') because I…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
5
votes
1 answer

Why is StringTokenizer giving different outputs when used in a while loop and a for loop

I used StringTokenizer to get the tokens of a string. But I get two different outputs when I tried to print all the tokens in that StringTokenizer, using a for-loop and a while-loop. String string="She is an attractive girl, isn't…
5
votes
5 answers

How to get numbers out of string?

I'm using a Java StreamTokenizer to extract the various words and numbers of a String but have run into a problem where numbers which include commas are concerned, e.g. 10,567 is being read as 10.0 and ,567. I also need to remove all non-numeric…
Mr Morgan
  • 543
  • 4
  • 7
  • 17
5
votes
3 answers

Read data from a text file and create an object

I need some help: I'm making a Supermarket simulation on Java, but I've got one problem, I have a text file (Stock.txt) where I have all the supermarket stock on it for example: 0-Bakery-Chocolate Cake-$12.5-250 1-Meat-Premium…
DkRckr12
  • 183
  • 1
  • 1
  • 3
5
votes
4 answers

Tokenize problem in Java with separator ". "

I need to split a text using the separator ". ". For example I want this string : Washington is the U.S Capital. Barack is living there. To be cut into two parts: Washington is the U.S Capital. Barack is living there. Here is my code : //…
poiuytrez
  • 21,330
  • 35
  • 113
  • 172
5
votes
2 answers

How to Tokenize String with Commas and Line Delimiter

I'm making a simple String Tokenizer in Swift like I would in Java...but it's really not working out for me. The end of each line in my data source delimited with "^" and the data is separated by comma's. For example: "string 1,string 2,string…
stepheaw
  • 1,683
  • 3
  • 22
  • 35
5
votes
2 answers

elasticsearch custom tokenizer - split token by length

I am using elasticsearch version 1.2.1. I have a use case in which I would like to create a custom tokenizer that will break the tokens by their length up to a certain minimum length. For example, assuming minimum length is 4, the token "abcdefghij"…
5
votes
3 answers

C# Tokenizer - keeping the separators

I am working on porting code from JAVA to C#, and part of the JAVA code uses tokenizer - but it is my understanding that the resulting array from the stringtokenizer in Java will also have the separators (in this case +, -, /, *, (, )) as tokens. I…
Ipster
  • 115
  • 1
  • 2
  • 10
4
votes
1 answer

Cloning value of a stringTokenizer java

I have a stringTokenizer set up and I want to have a copy of it for another process. Is there a way of doing this? My code: StringTokenizer itr = new StringTokenizer(theBigString); itr.nextToken(); // My goal is to get a new StringTokenizer after…
suman
  • 195
  • 13
1
2
3
41 42