I was set up to replace the & with & in the compiler and when I ran it, it gave me &
I did the same thing in the Windows version and it did it correctly, & became &.
Bob
I was set up to replace the & with & in the compiler and when I ran it, it gave me &
I did the same thing in the Windows version and it did it correctly, & became &.
Bob
Similar result here. Apparently the Mac version applies the replacement rules twice, whereas the Win version only once…
Yeah, I encountered something like that moving to MacScriv.
In my case I was able to take advantage of case-sensitivity as a work around, but that probably won’t help with an &.
A bit more info: viewtopic.php?f=2&t=30002
I played around with replacing & with &, and found a work-around.
In the replacements tab, you need two lines, the one that produces “&” and another to replace that with just “&”:
replace: & with &
replace: & with &
The second entry manages to catch the overzealous expansion of & without falling prey to the same problem. Don’t check any of the boxes for case sensitivity, regex, or whole word.
I can make that change, but I am curious is the list is processed twice, or is it something wacky the &.
Bob
Presumably not processed twice, but processed sequentially.
Yeah, I’m not entirely certain if it processes the list more than once (it does seem to), but it does do each replacement in the order of the list.
The problem doesn’t have to do with the & character however; the linked topic in SarsenLintel’s response shows that the issue occurs when you are replacing a string of characters with another set of characters that contain the original string in its entirety. So since & is replaced with a string of characters which contains & (the entire contents of the “replace” column), you get this behavior.
Replicating the behavior is easy, assuming the replacements are happening twice:
If you create a new file in TextEdit, and enter something that contains ‘&’, you can do an experiment to show why it does seem to do everything twice, and why this work-around works;
A. Do a search and replace, searching for & and replacing with &
The result will be &
B. Now repeat the same search and replace again.
The result will be &
C. Now search for & and replace with &
Result: &
D. Do the search and replace again.
Result: no change.
If you do it in the order A,C,B,D, you get the same end result; so it doesn’t make a difference if the whole list is processed and then processed again, or if each line is processed twice before going to the next line.
You can do the above with any set of characters. Try replacing “more” with “more stuff” twice and you’ll get “more stuffstuff”.
AH… GOT IT!
From the Programming stand point.
It would appear: on the Mac the Replace Function is not incrementing the starting placement correctly when it does the replacement, to step over the Replaced text [(Current Character Position + LengthOf(Replacement String))]. Thus & > & > then & It isn’t ofter that you do a Search and replace on a Single Character and most of those would be Special Programming Characters.
Understanding the error is first step a effective workaround or effective Text Replacement, if you are using Text Replacement on a regular basis.
Thanks