Java如何将Token转换为字符串?
似乎无法弄清楚如何将令牌(StringTokenizer)转换为字符串。
我有一个 String[] 关键字,并且我从文本文件中读取了多行文本。 StringTokenizer 用于将句子切碎,,, 此时我需要将每个 Token(Token 的字符串表示形式)传递给函数进行单词分析。
有没有一种简单的方法可以从令牌中提取字符串值?
任何帮助都很感谢大家...
非常有帮助的家伙再次感谢!
Cant seem to figure out how to convert a Token (StringTokenizer) into a String.
I have a String[] of keywords, and I read in multiple lines of text from a text file.
StringTokenizer is used to chop the sentence up,,, at which point I need to pass each Token (the String representation of the Token) to a function for word analysis.
Is there a simple way to extract the string value from the token?
Any help appreciated guys....
Great help guys thanks again!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用方法
nextToken()
以字符串形式返回令牌Use the method
nextToken()
to return the token as a stringnextToken()< /code>
调用 StringTokenizer,已返回
String
。您不需要将该String
转换为String
。令牌只是较大字符串的一小部分(字符串)。令牌用于各种形式的处理,并且需要一个单词(单词令牌)来区分项目的类别和特定项目。
适合以下标记(所有标记都是字符串):
nextToken()
called on a StringTokenizer, already returns aString
. You don't need to convert thatString
to aString
.A Token is just a small (string) portion of a larger String. Tokens are used in various forms of processing, and a word (the word token) is needed to differentiate the category of items from the specific items.
Would lend itself to the following tokens (all of which are strings):
StringTokenizer 现在是 Java 中的遗留类。从 Java 1.4 开始,建议对 String 使用 split() 方法,该方法返回 String[]。
http:// /download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
StringTokenizer is now a legacy class in Java. As of Java 1.4 it is recommended to use the split() method on String which returns a String[].
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)