4 ms·
What exactly is a substring function, and what makes it different than a regex?
by lilbobbytables 10y ago
What exactly is a substring function, and what makes it different than a regex?
- solipsism 10y agoMy guess is they're searching for the first non-whitespace character, reverse-searching for the last non-whitespace character, and then using String.Substring to return only what's in the middle. As to why they're not using String.Trim (https://msdn.microsoft.com/en-us/library/t97s7bs3(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/t97s7bs3(v=vs.110)....), maybe it's because String.Trim doesn't seem to know about the 200c whitespace character.
- dingo_bat 10y agoFrom what I understood, trim would work perfectly. It's 200 spaces not a single 200 width character.
- solipsism 10y agoYou're misreading the regex. \u200c is a single whitespace character. http://www.fileformat.info/info/unicode/char/200c/index.htm http://www.fileformat.info/info/unicode/char/200c/index.htm
- dingo_bat 10y agoBut that's a weird character to put in a comment line! I don't get how this would happen accidentally.
- pyre 10y agoYou really can't think this way when accepting input from users.
- Piskvorrr 10y agoRunaway automatic search-and-replace? There's no way to distinguish intent.
- dingo_bat 10y agoRunaway search and replace won't put a single 200 width whitespace character AFAICT
- Piskvorrr 10y agoThat's the meaning of "runaway" - Notepad++ had a search&replace that went into a somewhat random, long and uninterruptible loop if you were replacing using some types of regex and searhing forward in the file - you had to search backwards.
- brokenmachine 10y agoWhat difference does it make if it got in there accidentally or on purpose? Stackoverflow is a programmers site, you must expect that a programmmer might go, "Hmm, they're trimming whitespace, wonder what happens if I put 20,000 unicode whitespace characters in there instead of normal whitespace"?