如何将 a 的内容设置JTextPane为 a String array?我正在制作一个记忆应用程序,它删除用户在 a 中输入的随机单词JTextPane并将其替换为下划线。我想将用户输入的内容转换为 a string array,每个索引都是一个单独的单词。
有人对如何实现这一点有任何想法吗?
任何和所有的帮助表示赞赏!
Some tips:
JTextArea or JTextPane through getText() method. It will return a StringString by white spaces. Take a look to this answer: How do I split a string with any whitespace chars as delimiters?. You'll have a String[] as desired.JTextArea or JTextPane.您可以使用javax.swing.text.Utilities. 它有2种方法
public static final int getWordStart(JTextComponent c, int offs)
public static final int getWordEnd(JTextComponent c, int offs)
您可以从 0 偏移量开始并搜索下一个单词结尾。然后在第一个单词的结尾等之后开始搜索下一个单词。
这些方法使用依赖于语言环境的分词迭代器。
BreakIterator.getWordInstance(c.getLocale())