你好,我做一个程序,可以突出串入的WebView(Android)和我停留在彩色一个替换字符串,这段代码Java字符串,的replaceAll(),但保留情况下,原始字符串
String[] arr = "LION SAVANA".split(" ");//i split textview string to have words (here we suppose that user entered : "lion savana"
String finalText = "the lion is a species of mamifer living into the savana"
for (String ss : arr) {
if (ss.length() > 2) {
ss = ss.replace("*","");
finalText = finalText.replaceAll("(?i)" + ss, "<b style = \"color:#2575ff\";>" + ss + "</b>");//finally here i replace all lion or savana occurrences by blue ones -> but i not keeps case :(
}
}
这个循环后的文字将“LION是mamifer活到SAVANA的物种”,为蓝色像预期,但用大写的,因为我不希望
请给出一个输入和输出的例子。 –
那真正的问题是什么? – tnw
问题是:用户在textview中输入“FOO”,但用我的代码“Foo”的所有“foo”或“foo”将被替换为“FOO”,并且我想保留原始案例(上,下,或混合) – Noj