stringtokenizer

Finding if conditions in .java file

ⅰ亾dé卋堺 提交于 2019-12-12 03:56:41
问题 I tried to make method which will finding all if conditions in .java file (I assume that file contain only correct if instructions). It should count all "if", but not that which are sorrounded with comments or treaded as string. I tried to solve this problem with StringTokenizer, but I don't know how elided line after "//" sign and strings sorrounded with " ".Is it possible to realize this problem in this way, at all? public int getIfCount() { int counter = 0; String t = ""; try { FileReader

String tokenization in java (LARGE text)

删除回忆录丶 提交于 2019-12-11 12:06:47
问题 I have this large text (read LARGE). I need to tokenize every word, delimit on every non-letter. I used StringTokenizer to read one word at a time. However, as I was researching how to write the delimiter string ("every non-letter") instead of doing something like: new StringTokenizer(text, "\" ();,.'[]{}!?:”“…\n\r0123456789 [etc etc]"); I found that everyone basically hates StringTokenizer (why?). So, what can I use instead? Dont suggest String.split as it will duplicate my large text. I

java StringTokenizer unexpected results

淺唱寂寞╮ 提交于 2019-12-11 04:08:43
问题 i have the following code which will tokenize the string to create list of Objects: import java.util.StringTokenizer; public class TestStringTokenizer { private final static String INTERNAL_DELIMETER = "#,#"; private final static String EXTERNAL_DELIMETER = "#|#"; public static void main(String[]aregs){ String test= "1#,#Jon#,#176#|#2#,#Jack#,#200#|#3#,#Jimmy#,#160"; StringTokenizer tokenizer = new StringTokenizer(test, EXTERNAL_DELIMETER); while(tokenizer.hasMoreElements()){ System.out

Get Position in Original String from `StringTokenizer`

試著忘記壹切 提交于 2019-12-10 16:19:52
问题 I need to get the space-separated tokens in a string, but I also need to know the character position within the original string at which each token starts . Is there any way to do this with StringTokenizer . Also, as I understand it, this is a legacy class; is there a better alternative to using StringTokenizer . 回答1: You should always use String#split() to split your string rather than StringTokenizer . However, since you also want the position of the tokens in your string, then it would be

Tokenize problem in Java with separator “. ”

蓝咒 提交于 2019-12-10 15:42:58
问题 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 : // Initialize the tokenizer StringTokenizer tokenizer = new StringTokenizer("Washington is the U.S Capital. Barack is living there.", ". "); while (tokenizer.hasMoreTokens()) { System.out.println(tokenizer.nextToken()); } And the output is unfortunately :

Error whilst using StringTokenizer on text file with multiple lines

醉酒当歌 提交于 2019-12-09 01:52:51
问题 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

java StringTokenizer - can nextToken return null?

你说的曾经没有我的故事 提交于 2019-12-08 03:15:02
问题 Is there any case where StringTokenizer.nextToken will return null? I'm trying to debug a NullPointerException in my code, and so far the only possibility I've found is that the string returned from nextToken() returned null. Is that a possibility? Didn't find anything in the java doc. Thanks 回答1: nextToken() throws NoSuchElementException if there are no more tokens in the tokenizer's string; so I would say that it doesn't return null. http://download.oracle.com/javase/1.4.2/docs/api/java

RegEx split string with on a delimeter(semi-colon ;) except those that appear inside a string

烂漫一生 提交于 2019-12-08 02:50:00
问题 I have a Java String which is actually an SQL script. CREATE OR REPLACE PROCEDURE Proc AS b NUMBER:=3; c VARCHAR2(2000); begin c := 'BEGIN ' || ' :1 := :1 + :2; ' || 'END;'; end Proc; I want to split the script on semi-colon except those that appear inside a string. The desired output is four different strings as mentioned below 1- CREATE OR REPLACE PROCEDURE Proc AS b NUMBER:=3 2- c VARCHAR2(2000) 3- begin c := 'BEGIN ' || ' :1 := :1 + :2; ' || 'END;'; 4- end Proc Java Split() method will

Split string using pl/sql using connect level on null value

瘦欲@ 提交于 2019-12-07 13:21:35
问题 I'm using this following code in Oracle pl/sql (Version: Oracle Database 11g Release 11.2.0.1.0) select regexp_substr('A~B~C','[^~]+',1,level) output from dual connect by level <= length(regexp_replace('A~B~C','[^~]+')) + 1 which gives the following results row1: A row2: B row3: C That's perfect, however should I want to give a null value, ie: select regexp_substr('~B~C','[^~]+',1,level) output from dual connect by level <= length(regexp_replace('~B~C','[^~]+')) + 1 I expected and wanted the

How to find count and names of distinct characters in string in PL/SQL [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-07 10:20:45
问题 This question already has an answer here : How can I get the unique characters from a string in Oracle? (1 answer) Closed 6 years ago . I'm quite new to PL/SQL and I need to get the names and count of the distinct characters in a string. E.g. if I have a string str="helloexample" , I need to get output of distinct characters in str , i.e. heloxamp . How can I do this? 回答1: You can use regular expression as follows: SET serveroutput ON DECLARE str VARCHAR2(20):='helloexample'; str_length