gpt4 book ai didi

java - 如何保留在相同样式的文本内容中选择多次出现的相同字符串?

转载 作者:行者123 更新时间:2023-12-01 12:59:34 25 4
gpt4 key购买 nike

如何保留在相同样式的文本内容中选择的同一字符串的多次出现?可以使用setSelection()选择单个出现的情况。有类似的选择吗?

最佳答案

使用StyleRange设置字符串的多次出现。

片段:

    String searchKey = "hello";
String content = styledText.getText(); // StyledText instance
int index = content.indexOf(searchKey, 0);
do {
if (index != -1) {
StyleRange styleRange = new StyleRange(index, searchKey.length(), Display.getCurrent().getSystemColor(
SWT.COLOR_BLACK), Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
styledText.setStyleRange(styleRange);
index = content.indexOf(searchKey, index + 1);
} else {
System.out.println("End of search");
break;
}

} while (index != -1);

引用this文章examples here关于风格范围。

关于java - 如何保留在相同样式的文本内容中选择多次出现的相同字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23624053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com