- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是使用 BreakIterator 将“<,Bold,>”转换为“< Bold>”(“<”和“B”之间没有空格)
说字符串“这是一个测试。”是我的输入
public static List<String> getWords(String text) {
List<String> words = new ArrayList<String>();
BreakIterator breakIterator = BreakIterator.getWordInstance();
breakIterator.setText(text);
int lastIndex = breakIterator.first();
while (BreakIterator.DONE != lastIndex) {
int firstIndex = lastIndex;
lastIndex = breakIterator.next();
if (lastIndex != BreakIterator.DONE) {
String t = text.substring(firstIndex, lastIndex);
words.add(t);
}
}
return words;
}
getWords(String) 返回 <,Bold,>, ,This, ,is, ,a, ,test。
我已经尝试过:
String t = text.substring(firstIndex, lastIndex);
if (t != "<" || t != ">" || t != "/" || t != ">") System.out.println("Char Not Skipped " + t); else System.out.println("Char Skipped" + t);
//if (text.charAt (firstIndex - 1) == '<') t = "<" + t;
//if (text.charAt (lastIndex + 1) == '>') t += ">";
//if (text.charAt (lastIndex + 1) == '/' && text.charAt (lastIndex + 2) == '>') t += "/>";
//System.out.println(t);
words.add(t);
返回的只是 Char Not Skipped。
最佳答案
我不确定我是否正确地回答了您的问题。
如果要删除全部,
在你的字符串中你可以轻松地做到:
String s = "<,Bold,>, ,This, ,is, ,a, ,test";
String newString = s.replace(",", "");
System.out.println(newString);
输出如下:
This is a test
如果您只想删除<,
和,>
你可以使用:
String s = "<,Bold,>, ,This, ,is, ,a, ,test";
String newString = (s.replace("<,", "<")).replace(",>", ">");
System.out.println(newString);
输出为
<Bold>
, ,This, ,is, ,a, ,test
关于java - 使用 BreakIterator 跳过非字母字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34021411/
我使用 BreakIterator.getWordInstance 将中文文本拆分为单词。这是我的例子 import java.text.BreakIterator; import java.util
我的目标是使用 BreakIterator 将“”转换为“”(“ getWords(String text) { List words = new ArrayList(); Break
我正在使用 java.text.breakIterator用于迭代单词(这不是迭代器,是的,我已经注意到,无需告诉我)。为什么我不能把它作为一个实际的迭代器?即为什么我不能这样做: Iterator
我正在使用 BreakIterator 来计算字符串中可见字符的数量。这非常适合英语。但对于印地语,它无法按预期工作。 下面的字符串长度为3,但视觉上被视为单个字符。 ज्य 当我使用 BreakIt
我尝试使用 BreakIterator Java 将包含引用的段落拆分为句子。 这是我的段落,其中包含我想要拆分的引文: "People are now getting smarter and mor
我想了解如何使用 icu::BreakIterator 来查找特定的单词。 例如我有以下句子: To be or not to be? That is the question... break 迭代
我有一个 unix 文本文件,我想在我的 Android 应用程序中阅读并将其拆分成句子。但是我注意到 BreakIterator 将一些换行符视为句子分隔符。我使用以下代码读取文件并将其拆分为句子(
我想修改 ICU 源代码,但它对我来说非常难以理解,我无法找到我正在寻找的部分。 我希望找到有关 BreakIterators 实现的代码(并希望找到一些解释注释/文档)。有谁知道这是 ICU C++
我使用 ICU 中断迭代器进行了裁剪。在 the example ,他们建议使用以下代码遍历所有边界: void listWordBoundaries(const UnicodeString& s)
我正在 Android 中制作自己的文本处理器(蒙古语的自定义垂直脚本 TextView)。我以为我必须自己找到所有换行位置才能实现换行,但后来我发现了 BreakIterator .这似乎找到了各种
我正在做一个从 java 到 c# 的转换项目,是否有任何与 BreakIterator 等效的 c# ?我在尝试 IEnumerator ,但找不到 iterator.SetText()下面的用法,
我不小心回答了一个question原始问题涉及将句子拆分为单独的单词。 和作者suggested to use BreakIterator标记化输入字符串,有些人喜欢这个想法。 我只是不明白这种疯狂:
以下代码适用于 Android 4,但在 Android 2 中会导致 IllegalArgumentException。 有什么线索吗? Locale currentLocale = new Loc
我是一名优秀的程序员,十分优秀!