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
0
votes
2 answers

Exception to cause EOL with streamtokenizer?

I am writing a small calculator that goes through the input in token form by using streamtokenizer. However, when catching an exception I want it to either ignore all other exceptions, or move to the EOL. I can't just break as the progream isn't…
user1476968
  • 307
  • 1
  • 5
  • 10
0
votes
1 answer

Using StringTokenizer in Java to Split a Path Platform Independent

I am trying to split a filepath using a StringTokenizer independent of the Platform (Windows/Solaris/Linux). For example: c:\folder1\folder2\sample.xls would turn into folder1, folder2, sample.xls in the StringTokenizer and…
aruuuuu
  • 1,605
  • 2
  • 22
  • 32
0
votes
2 answers

Need help in strtok function when the first token is null

Need help in strtok function #include #include int main() { char string[100], *ptr = NULL; memset(string, 0, 100); strcpy(string, "abc#efg#xyz"); ptr = strtok(string, "#"); fprintf(stderr, "ptr = [%s]\n",…
neo
  • 55
  • 12
0
votes
1 answer

reading data file into string using string tokenizer

hi I have this code for reading text file into string void addStu (BST_TREE* list) { // Local Declarations COMPANY* stuPtr; FILE* fp; int i = 0; char fileName[25]; char buffer [100]; char* tempString; // Statements stuPtr =…
bluebk
  • 169
  • 1
  • 6
  • 21
0
votes
3 answers

Find Comments with StringTokenizer

I used the following code to count the number of comments in a code: StringTokenizer stringTokenizer = new StringTokenizer(str); int x = 0; while (stringTokenizer.hasMoreTokens()) { if (exists == false &&…
Dilshi
  • 543
  • 3
  • 7
  • 17
0
votes
3 answers

How can I make StringTokenizer replace a letter properly?

Note: I have to use StringTokenizer for this program (it's for an assignment) I'm trying to get this string "Java Programming." to say "J@v@~~~Progr@mming." with StringTokenizer. I have 2 problems with the following code... My first…
Emmanuel Henri
  • 153
  • 3
  • 27
0
votes
2 answers

Tokenizing or Splitting String

I am having trouble tokenizing or splitting string on the basis of some delimeter. There are two type of Strings that I need to tokenize. Following is the pattern: a/b/c/d and a/b//d I am confused how to get both parsed by one function.…
Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
0
votes
3 answers

Can StringTokenizer countTokens ever be zero?

I just found a piece of Java code inside a method: if (param.contains("|")) { StringTokenizer st = new StringTokenizer(param.toLowerCase().replace(" ", ""), "|"); if (st.countTokens() > 0) { ... } } else { return…
András Hummer
  • 960
  • 1
  • 17
  • 35
0
votes
2 answers

input/output of an array of objects in Java and StringTokenizer

I have a problem however i'm not quite sure where it lies. I am reading data from a text file, NRL team data to be specific. The data is split up with commas and the data is: club name, club mascot, club alias. There are 20 or so lines of this. I…
drcoding
  • 153
  • 1
  • 3
  • 15
0
votes
2 answers

Obj C equivalent to Java StringTokenizer return delimiters

I am trying to parse a large string in order to isolate words and all punctuation. Java has the following constructor for its StringTokenizer class. public StringTokenizer(String str, String delim, boolean returnDelims) Notice the last parameter.…
Jack Stone
  • 37
  • 1
  • 6
0
votes
3 answers

.nextToken() encountere a space it throws an java.util.NoSuchElementException

I have a csv file that contain one line; '2013-05-25 23:59:59','-126125372','299134596','-1272989684','1826558680','-441013765','-441013765' Every time the token encounter a space (e.g. "2013-05-25 23:59:59") it throws a error. Im using a…
gibson
  • 3
  • 1
  • 3
0
votes
1 answer

Java Project: Having issues with string tokenizer

This is what I have so far: //class to calculate grades import java.util.StringTokenizer; public class Grades { //variables private String studentName; private int studentId; private double[] quizGrade; private double[]…
0
votes
3 answers

Explanation of code segment

What are the values of s1, s2, and s3 after the following code executes? String s1, s2, s3=""; StringTokenizer line = new StringTokenizer("You are cool"); s1 = line.nextToken(); s2 = line.nextToken(); while (line.hasMoreTokens()) s3…
hjg hjg
  • 111
  • 2
0
votes
2 answers

Tokenize a String on multiple delimiters

I want to tokenize a String to key value pairs. But key has characters like underscore, comma, space etc. The key value pair is separated by = character Example: key=value start_time="2013-03-01 03:20:40" Key withspace=space1 two …
Dheeraj Joshi
  • 3,057
  • 8
  • 38
  • 55
0
votes
2 answers

Evaluating a String expression as an Integer?

I'm trying to evaluate a string from left to right as an Integer with numbers between 0-9 and the four basic operators (like "5+8+(8/4)" should evaluate as 15 or "9+((3+4)*5)" as 44 or "4+2*6" as 36 since 4+2 is calculated first due to all operators…
Adam
  • 355
  • 1
  • 6
  • 12