String a ="the STRING TOKENIZER CLASS ALLOWS an APPLICATION to BREAK a STRING into TOKENS. ";
StringTokenizer st = new StringTokenizer(a);
while (st.hasMoreTokens()){
System.out.println(st.nextToken());
Run Code Online (Sandbox Code Playgroud)
鉴于以上代码,输出如下,
the
STRING TOKENIZER CLASS
ALLOWS
an
APPLICATION
to
BREAK
a
STRING
into
TOKENS.
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是为什么"STRING TOKENIZER CLASS"被合并成一个标记????????
当我尝试运行此代码时,
System.out.println("STRING TOKENIZER CLASS".contains(" "));
Run Code Online (Sandbox Code Playgroud)
它打印出有趣的结果,
假
这听起来不合逻辑吗?我不知道出了什么问题.
我发现了原因,这个空间在某种程度上被Java认为不是有效空间.但是,我不知道从前面处理到我发布的代码是怎么回事.
伙计们,我需要强调的是,下面的代码首先在上面的代码之前运行.
if(!suspContentCollector.isEmpty()){Iterator i = suspContentCollector.iterator(); String temp =""; while(i.hasNext()){temp + = i.next().toLowerCase()+""; } StringTokenizer st = new StringTokenizer(temp);
while (st.hasMoreTokens()){
temp=st.nextToken();
temp=StopWordsRemover.remove(temp);
analyzedSentence = analyzedSentence.replace(temp,temp.toUpperCase());
}
}
Run Code Online (Sandbox Code Playgroud)
因此,一旦它被改为大写,某些地方似乎出现了问题,我意识到只有某些空间无法识别.这可能是从文档中检索文本的原因吗?
以下代码,
字符串a …
无论如何我们可以直接访问stringTokenizer中的某个(比方说20)元素.我时不时地只需要它中的某个元素而不需要其他元素,但我必须遍历所有元素.
编辑:我也想忽略空元素.
我错过了什么吗?
我正在使用Java,我正在使用StringTokenizer来获取我的String的一部分,但问题是当我使用"StringTokenizer"时,我的结果的一部分没有出现这是我的java代码:
for(String iopp:opp){
StringTokenizer tokenizer = new StringTokenizer(iopp,"form:blocConfigurations:configurations:0:parametrage:options:");
while(tokenizer.hasMoreTokens()){
ind.add(tokenizer.nextToken());
}
}
logger.info("Mes indices sont :"+ind);
Run Code Online (Sandbox Code Playgroud)
在我的控制台中:
what was it :[form:blocConfigurations:configurations:0:parametrage:options:1, form:blocConfigurations:configurations:0:parametrage:options:6, form:blocConfigurations:configurations:0:parametrage:options:9, form:blocConfigurations:configurations:0:parametrage:options:17, form:blocConfigurations:configurations:0:parametrage:options:20, form:blocConfigurations:configurations:0:parametrage:options:21, form:blocConfigurations:configurations:0:parametrage:options:22]
17:13:45,876 INFO [com.sfr.price.functionalTest.scenario.impl.AJLINGE.etapeParametrerOption](821) [] Mes indices sont :[1, 6, 9, 17, 2, 21, 22]
Run Code Online (Sandbox Code Playgroud)
StringToknizer工作得非常好,但我不明白为什么在这个元素形式:blocConfigurations:configurations:0:parametrage:options:20它只显示2而不是20
提前致谢
我有一个字符串,我应该在课程中使用 StringTokenizer。我已经制定了如何实施该项目的计划,但我找不到任何关于如何为每个字符设置分隔符的参考。
基本上,像“Hippo Campus is a party place”这样的字符串,我需要为每个字符划分标记,然后将它们与一组值进行比较,然后将特定的值与另一个值交换。我知道如何做其他所有事情,但是分隔每个字符的分隔符是什么?
我在Oracle中有一个存储过程,如下所示:
CREATE PROCEDURE MY_TEST_PROC(
CUR OUT SYS_REFCURSOR,
PARAM_THAT_WILL_BE _USED_INSIDE_WHERE_IN
)
AS
BEGIN
OPEN CUR FOR
SELECT *
FROM MY_TABLE
WHERE COL1 IN (here I want to put values received from C#)
END;
Run Code Online (Sandbox Code Playgroud)
在ASP.NET应用程序端,我有一个包含多个选项的select元素.我想在WHERE子句中使用这些列表项.我知道我可以在我的存储过程中有一个VARCHAR2输入参数,从列表项中创建一个逗号分隔的字符串,然后将其发送到过程.这样做有两个问题:
如何将这些列表项发送到存储过程并在WHERE IN子句中使用它们?我正在使用ODP.NET并听说过UDT,但不知道如何使用它.
我试图在delim"//"上打破字符串.我的字符串也包含"/"和StringTokenizer给出奇怪的结果,它也打破了"/"上的字符串.
String mStr = "abcd//aaa//32434//3/34343";
StringTokenizer tok = new StringTokenizer(mStr, "//");
while(tok.hasMoreTokens()){
System.out.println(tok.nextToken());
}
Run Code Online (Sandbox Code Playgroud)
结果是
abcd
aaa
32434
3
34343
Run Code Online (Sandbox Code Playgroud)
而预期的结果是
abcd
aaa
32434
3/34343
Run Code Online (Sandbox Code Playgroud)
为什么会这样,它的解决方案是什么?我不想用其他字符替换"/".
可能重复:
在java中匹配"."
我有一个字符串1.2.4,我想拆分,2并将其与我得到的另一个字符串进行比较.
我正在尝试执行以下操作
StringTokenizer old_ver = new StringTokenizer(oldVersion, ".");
int oldVer = Integer.parseInt(old_ver.nextToken());
oldVer = Integer.parseInt(old_ver.nextToken());
StringTokenizer new_ver = new StringTokenizer(newVersion, ".");
int newVer = Integer.parseInt(new_ver.nextToken());
newVer = Integer.parseInt(new_ver.nextToken());
if (oldVer == newVer) {
return true;
}
Run Code Online (Sandbox Code Playgroud)
是否有更好的方法来使用它 .Split()
我想在java中用它的标记拆分一个字符串.例如;
String s = "A#B^C&D!ased&acdf@Mhj%"
String temp[] = s.split("[#^&!@%]+");
Current output :-
temp[0] = A
temp[1] = B
temp[2] = C
temp[3] = D
temp[4] = ased
output which i want :-
temp[0] = A#
temp[1] = B^
temp[2] = C&
temp[3] = D!
temp[4] = ased&
My current approach of doing is
pos = find the index of the token in string
pos = add the size of the token in pos
charAtPos = getcharfrom string at index pos …Run Code Online (Sandbox Code Playgroud) 我有以下代码将标记字符串以创建对象列表:
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.println(tokenizer.nextElement());
//later will take this token and extract elements
}
}
}
Run Code Online (Sandbox Code Playgroud)
我期望的输出是
1#,#Jon#,#176
2#,#Jack#,#200
3#,#Jimmy#,#160
我得到的是:1
,
乔恩
,
176
2
,
杰克
,
200
3
,
吉米
,
160
如果我将内部分隔符改为某些东西,它会正常工作为什么会发生这种情况?
我正在尝试读取文本文件并使用java中的字符串标记生成器实用程序单独拆分单词.
文本文件如下所示;
a 2000
4
b 3000
c 4000
d 5000
Run Code Online (Sandbox Code Playgroud)
现在,我要做的是从文本文件中获取每个单独的字符并将其存储到数组列表中.然后我尝试打印arraylist中的每个元素.
这是我的代码;
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 = fileSpecified.concat(".txt");
String line;
System.out.println ("file Specified = " + fileSpecified);
ArrayList <String> words = new ArrayList<String> ();
try {
FileReader fr = new FileReader (fileSpecified);
BufferedReader br = new BufferedReader (fr);
line = br.readLine();
StringTokenizer token;
while ((line = br.readLine()) != null) {
token = …Run Code Online (Sandbox Code Playgroud)