ReplaceAll( "abcd", "c", "e" ) returning an empty string

A quite big and old application that has always worked well is failing only for 3 users out of thousands. After weeks I haven’t been able to discover what those users have in common. Basically, for those 3 users a ReplaceAll call results in an empty string. The source string is not empty and none of the others are. I just wonder what can cause say ReplaceAll( “abcd”, “c”, “e” ) to return “”. The problem started after porting the application to Cocoa. I read all posts about normalization but the strings here are all created and manipulated from inside the app. Anybody else has faced that problem?

Thanks, Stan

are you say the command [ ReplaceAll(“abcd”,“c”,“e”) ] returns “”
or is that just an example? because there is no way that explict syntax would return anything other than “abed”

If you are using this as an example, and in reality you have variables or derived string sequences then we will need much more information… And if this is NOT an example, then I’d ask why not just hard code “abed”

A little bit more information would be better. Especially about the real strings that are used.

Yes, I’ve had problems like this for hebrew encoding.

It is quite simple, I sell an app that, among other things, replaces tags by user text. Imagine [Firstname] replaced by data from a list. Well, in 99,999% of cases it works flawlessly and as expected. I have thousands of users using the app and only with 3 of them it doesn’t work, it never works, tags are not replaced, the whole text is removed, the ReplaceAll I use output an empty string, that is ReplaceAll( “abcd”, “c”, “e” ) to return “”… I have never been able to reproduce the problem myself, reason why I am posting here… to get some clues. The app is a document based app so in all cases I ask for the full document, but nothing, it works for me, but not for those 3 users… :-/ … Unbelievable… :frowning: … Last user is using plain english text…

If you are displaying the result in a TextField or TextArea after calling ReplaceAll, make sure it doesn’t have any chr(0) characters in it… Especially at the beginning. The field will see that as a terminator and you could get nothing.

For debug, maybe a write to a text file the Replace Source, find and replace + returned string may be a good idea (sent to the 3 that have troubles).
The 3 that have troubles can then send back to you these files and with an hex editor, you can watch carefully what’s inside the files (as Chr(0) … Chr(31) are invisibles just like Greg says) and found what the trouble is ?

Without example strings from your three users there is no way to tell what’s going on. Are you filtering out anything that could pose a problem, like unbalanced [ ] for example?

Hi Stanley!

Do you know where these users are from? Do you know that encoding they are using?
What OS version?

Alex

I wonder if that old code at the end of the function maybe the culprit:

Exception err
If err IsA NilObjectException then
Log_Exception(“xxxxxxx (method)”, “Nil Object Exception”)
elseif err IsA OutOfBoundsException then
Log_Exception(“xxxxxxx (method)”, “Out of Bounds Exception”)
elseif err IsA TypeMismatchException then
Log_Exception(“xxxxxxx (method)”, “Type Mismatch Exception”)
elseif err IsA IllegalCastException then
Log_Exception(“xxxxxxx (method)”, “Illegal cast Exception”)
elseif err IsA StackOverflowException then
Log_Exception(“xxxxxxx (method)”, “Stack overflow Exception”)
End if

I mean, the function is called by a thread and I believe a ThreadEndException is caught by the code above right? Am I right? I can of course use modern code to handle the exception above and the problem may go away but why that ThreadEndException may be throw? I say ‘may’ because I have no confirmation yet the problem is caused by that.

Thanks.

[quote=274451:@Stanley Roche Busk]I wonder if that old code at the end of the function maybe the culprit:

Exception err
If err IsA NilObjectException then
Log_Exception(“xxxxxxx (method)”, “Nil Object Exception”)
elseif err IsA OutOfBoundsException then
Log_Exception(“xxxxxxx (method)”, “Out of Bounds Exception”)
elseif err IsA TypeMismatchException then
Log_Exception(“xxxxxxx (method)”, “Type Mismatch Exception”)
elseif err IsA IllegalCastException then
Log_Exception(“xxxxxxx (method)”, “Illegal cast Exception”)
elseif err IsA StackOverflowException then
Log_Exception(“xxxxxxx (method)”, “Stack overflow Exception”)
End if

I mean, the function is called by a thread and I believe a ThreadEndException is caught by the code above right? Am I right? I can of course use modern code to handle the exception above and the problem may go away but why that ThreadEndException may be throw? I say ‘may’ because I have no confirmation yet the problem is caused by that.

Thanks.[/quote]
Oh, I bet it’s a ThreadAccessingUIException. That’s new to Cocoa.

Actually not, the app works flawlessly in hundreds of computers, mine included. I get the problem on 4 installations. I have spent months in tracking that problem and the ThreadEndException is one of the thing I think can cause that but since everything works for me it is difficult to see if it is or not.

Does the method protected by that exception handling return the replaced value? If you’re getting some other kind of exception that is not in the list of things you’re checking for then it would return “” at the end.

you could use introspection to log the error type like:

Log_Exception(“xxxxxxx (method)”, Introspection.GetType( err).FullName)

and then you’d know if it was some other kind of exception like the thread UI exception, or something different. If the type of exception isn’t in your list then it would just return nothing.

I always suspect something to do with text encoding when such text matching goes wrong, but in that case it would just not do the replace rather than return nothing. It makes sense if it’s falling out of the work into the error handling but none of those things match then you wouldn’t get any return, but you also wouldn’t get any log output either.