stringtokenizer

StringTokenizer delimiters for each Character

泄露秘密 提交于 2019-12-02 08:06:10
I've got a string that I'm supposed to use StringTokenizer on for a course. I've got my plan on how to implement the project, but I cannot find any reference as to how I will make the delimiter each character. Basically, a String such as "Hippo Campus is a party place" I need to divide into tokens for each character and then compare them to a set of values and swap out a particular one with another. I know how to do everything else, but what the delimiter would be for separating each character? If you really want to use StringTokenizer you could use like below String myStr = "Hippo Campus is a

Using string tokenizer to set create arrays out of a text file?

一个人想着一个人 提交于 2019-12-01 20:31:43
Hey. You may have recently seen a post by me looking for help, but I did it wrong before, so I am going to start fresh and begin at the basics. I am trying to read a text file that looks like this: FTFFFTTFFTFT 3054 FTFFFTTFFTFT 4674 FTFTFFTTTFTF ... etc What I need to do is put the first line into a String as the answer key. Next, I need to create an array with the student ID (the first numbers). Then, I need to create an array that is parallel to the student ID that contains the student's answers. Below is my code, and I can't quite figure out how to get it to work like this, and I was

StringTokenizer - reading lines with integers

南楼画角 提交于 2019-12-01 11:04:09
I have a question about optimization of my code (which works but is too slow...). I am reading an input in a form X1 Y1 X2 Y2 etc where Xi, Yi are integers. I am using bufferedReader for reading lines and then StringTokenizer for processing those numbers like this: StringTokenizer st = new StringTokenizer(line, " "); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); The problem is that this approach seems time inefficient when coping with large data sets. Could you suggest me some simple improvement (I have heard that some integer parse int or regex can be

What is difference between hasmoreelements and hasmoretokens in stringtokenizer java? [duplicate]

独自空忆成欢 提交于 2019-12-01 09:38:46
问题 This question already has answers here : StringTokenizer method equivalence (2 answers) Closed 6 years ago . I am very much confused between hasmoreelements and hasmoretokens method of stringtokenizer. I want to know what's the difference Can anybody clear my confusion? Thanks 回答1: I want to know what's the difference From the Java API doc: hasMoreElements() Returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface. There is no

StringTokenizer - reading lines with integers

帅比萌擦擦* 提交于 2019-12-01 07:28:55
问题 I have a question about optimization of my code (which works but is too slow...). I am reading an input in a form X1 Y1 X2 Y2 etc where Xi, Yi are integers. I am using bufferedReader for reading lines and then StringTokenizer for processing those numbers like this: StringTokenizer st = new StringTokenizer(line, " "); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); The problem is that this approach seems time inefficient when coping with large data sets.

Error whilst using StringTokenizer on text file with multiple lines

好久不见. 提交于 2019-12-01 01:36:52
I'm trying to read a text file and split the words individually using string tokenizer utility in java. The text file looks like this; a 2000 4 b 3000 c 4000 d 5000 Now, what I'm trying to do is get each individual character from the text file and store it into an array list. I then try and print every element in the arraylist in the end. Here is my code; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.StringTokenizer; public static void main(String[] args) { String fileSpecified = args[0]; fileSpecified =

How to get numbers out of string?

空扰寡人 提交于 2019-11-30 21:41:03
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 characters from numbers where they might occur, e.g. $678.00 should be 678.00 or -87 should be 87. I believe these can be achieved via the whiteSpace and wordChars methods but does anyone have any idea how to do it? The basic streamTokenizer code at present is: BufferedReader br = new BufferedReader(new StringReader(text)); StreamTokenizer st = new

Tokenising a String containing empty tokens

ぐ巨炮叔叔 提交于 2019-11-30 15:13:43
问题 I have a seemingly simple problem of splitting a comma separated String into tokens, whereby the output should include empty tokens in cases where: The first character in the String is a comma. The last character in the String is a comma. Two consecutive commas occur. For example, for the String : ",abd,def,,ghi," should yield the output: {"", "abd", "def", "", "ghi", ""} . I have tried using String.split , Scanner and StringTokenizer for this but each gives a different undesired output

Tokenising a String containing empty tokens

家住魔仙堡 提交于 2019-11-30 13:55:41
I have a seemingly simple problem of splitting a comma separated String into tokens, whereby the output should include empty tokens in cases where: The first character in the String is a comma. The last character in the String is a comma. Two consecutive commas occur. For example, for the String : ",abd,def,,ghi," should yield the output: {"", "abd", "def", "", "ghi", ""} . I have tried using String.split , Scanner and StringTokenizer for this but each gives a different undesired output (examples below). Can anyone suggest an elegant solution for this, preferably using JDK classes? Obviously I

how to split strings in objective c

那年仲夏 提交于 2019-11-30 08:21:54
问题 How to split a string in objective-C? I am working on an short application that contains a date picker. I do display date get it from date picker and display it through a label. My main question is that how can I split the the date in to three separate strings? any one has idea about it? Thanks 回答1: You could use -[NSString componentsSeparatedByString:] or NSScanner to split the string, or use NSCalendar to extract the pieces of the date you're interested in. 回答2: Use something like