No, I didn’t miss that.
While I agree that understanding encodings is an important (albeit advanced) concept, if you already know the kind of data you will be dealing with, you can learn that nuance later. OP has their solution, which is guaranteed not to fail. In another scenario we can guide them toward encodings.
But that’s precisely why he should be guided away from using the byte-oriented functions: they’re NOT for use on encoded text - regardless of whether they happen to work in this edge case. He’s being set up for weird problems in the future by finding success here and then extrapolating this technique against problems where it will erratically cause problems.
In any case: sufficient notice has been given and now this is his decision to make, having at least been given enough information to make a sound decision.
Using ReplaceBytes or ReplaceAllBytes with UTF-8 strings will not result in a corrupt string. If your source string, oldString, and newString are all UTF-8 then you can use these functions and they will be case sensitive.
If your source string, old string, and new string are all UTF-8, then you don’t NEED to use ReplaceBytes or ReplaceAllBytes.
The original poster wanted a case sensitive replace and ReplaceBytes/ReplaceAllBytes will do what they want. It is probably the easiest way to do a case sensitive replace, and contrary to what some earlier posts suggested it is safe to use with UTF-8.
Yes, yes, we’ve been down this road several times. The point isn’t really that it will or won’t work – it’s more that it’s a bad form to suggest to someone who doesn’t understand the underlying technology (text encodings) because it will lead them down the road of manipulating string bytes in ways that aren’t safe because it worked in this one edge case.
It is especially galling since a really effective, safe solution using RegEx was suggested.
This is incorrect. Using the byte versions of Replace and ReplaceAll with UTF-8 will not cause damaged strings. It is a safe thing to do.
I’d argue that UTF-8 isn’t an edge case and using ReplaceBytes and ReplaceAllBytes with UTF-8 is safe. Arguably it’s also simpler to use than RegEx if all you want is a case sensitive replace.
Feel free to keep arguing that point, because that’s not the point I’m making.
ReplacAll is easy to understand. RegEx, I don’t know anything about it; even if I did, that’d still be more complicated than ReplaceAll.
Sometimes, you just can split meat with a fork or a spoon. Possibly not the best tool, but when it works and it’s what you can use, that’s fine.