String.Replace

thedesolatesoul

Expert
Licensed User
Longtime User
While I dont think this is a bug, it was one of the hardest things to debug.
Maybe it should be added to the tips section, or maybe there needs to be some kind of error catching.

This line:
B4X:
FolderPath = FolderPath.Replace(RootPath,"")

If RootPath = "", then this line creates an infinite loop, and the application dies ANR.
Maybe there should be a check if Target = Replacement, or atleast a runtime warning?
 

thedesolatesoul

Expert
Licensed User
Longtime User
I don't see that with this code
B4X:
FolderPath = "Some path"
RootPath = ""
FolderPath = FolderPath.Replace(RootPath,"")
Msgbox(FolderPath, "")
Perhaps some other condition is necessary
That is quite weird.
It is possible that it only happens on the emulator because its so slow!
I wrote that code a while a go, but since my router recently got fried, I was restricted to test on the emulator and I have only seen this behaviour on the emulator (running 2.2).
I added a Log command before and after that statement, and it does seem to stop at that exact statement. I dont see what should cause it to dwell on it too long, but maybe I can put it down to emulator(or 2.2) weirdness.

I found an issue fixed here: Issue 8807 - android - String.replace enters infinite loop when passed an empty string - Android - An Open Handset Alliance Project - Google Project Hosting
 
Top