0

问题:

为此使用 Java Tutorials™</a> 源代码。这是源代码。

我试过这个:

--following with another section of sorted words--
words.add("count");
words.add("cvs");
words.add("dce"); 
words.add("depth");
--following with another section of sorted words--

它工作得很好。但是,当我使用这个时:

--just a section of sorted words--
words.add("count");
words.add("cvs");
words.add("dce_iface"); 
words.add("dce_opnum");
words.add("dce_stub_data");
words.add("depth");
--following with another section of sorted words--

它确实会在我键入时显示dce_ifacedce但是当我键入时_os会显示其他内容dce_offset,例如偏移量来自words.add("fragoffset");列表中的某个位置。

我能做些什么来解决这个问题?先感谢您。

4

3 回答 3

1

这可能是因为代码中的这些行:

for (w = pos; w >= 0; w--) {
    if (! Character.isLetter(content.charAt(w))) {
        break;
    }
}

_不是字母字符,因此将其视为空格。您可以尝试将条件更改为:

char c = content.charAt(w);
if (! (Character.isLetter(c) || c == '_')) {
于 2010-04-26T15:00:20.103 回答
1

我想你必须在这里添加下划线作为“字母”

        // Find where the word starts
        int w;
        for (w = pos; w >= 0; w--) {
            if (!Character.isLetter(content.charAt(w))) {
                break;
            }
        }
于 2010-04-26T15:03:44.487 回答
1

它与本节有关insertUpdate()

// Find where the word starts
int w;
for (w = pos; w >= 0; w--) {
    if (! Character.isLetter(content.charAt(w))) {
        break;
    }
}

具体来说,Character.isLetter()为下划线字符返回 false。这意味着单词在下划线位置之后开始。

要解决这个问题,您需要修改if语句以允许您想在单词中使用任何非字母字符。您可以显式检查 '_' 或用于Chacter.isWhiteSpace()包含不是空格、制表符或换行符的所有字符。

于 2010-04-26T15:04:30.443 回答