简体   繁体   中英

How To replace the sequence \/ in android?

Issue in UI Is:

在此处输入图片说明

How to replace the sequence \\/ in android?

I Use below replace method but it show invalid escape sequences.

tempLabelForListView[i].replaceAll("\/", "")

You don't need to use String#replaceAll method, which takes a regex as parameter. Rather, just use String#replace method, and you need to escape the \\ with another backslash. And you need to re-assign the replaced string to your target string, since string is immutable, and the replacement will not affect the current string, rather return a new string: -

tempLabelForListView[i] = tempLabelForListView[i].replace("\\/", "");

As for String#replaceAll method, since it takes a regex, you would need to escape the backslash twice. Once for Java and once for regex . So, you would need 4 backslashes to make it work with replaceAll : -

tempLabelForListView[i] = tempLabelForListView[i].replaceAll("\\\\/", "");

But still, you don't need it here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM