Java: String replace doesn't find [closed]

≡放荡痞女 提交于 2019-12-13 08:35:25

问题


mystring.replace() doesn't find everything in my text e.g:

replace = (CalendarInfo.Monday + " " + String.valueOf(dayofmonth) + " " + String.valueOf(CalendarInfo.Month[monthofyear]).toString());
                   str= str.replace(replace, "Hello");

I've check the str and the replace but replace still doesn't do anything! str totally have replace string in it.

So why doesn't replace replace!?


回答1:


String str = "abcd".replace("ab", ""); //str is "cd"

That means your code works basically. But your replace string is not exactly in your source string.




回答2:


Probably because your assumption is wrong.

Maybe different count of (white) spaces, or different code (0x20 or 0xa0), or tab "\011"



来源:https://stackoverflow.com/questions/10144695/java-string-replace-doesnt-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!