If you write a string to a file using File.replaceWithText and then compare the result from File.loadFileAsString with your original string they may not be equal due to newline differences. How about adding a compareIgnoreNewlines method to String and CharacterFunctions to get around this?
In this you’re skipping the newlines altogether, but wouldn’t it be better to fail if there’s a newline in one string that isn’t in the other? That way it’d basically be a normal comparison, but one in which \n, \r, and \r\n are all considered to be equivalent.
It’d feel wrong to add something so specific to the library, though. Maybe a more generic method would be a comparison that lets you supply a set of characters that are considered equivalent? Or one where you supply the character comparison function…
Is it because of performance reasons that you’re not just writing string1.replace (T(“\r\n”), T(“\n”)).replaceCharacter (T(‘\r’), T(‘\n’)) == string2.replace (T(“\r\n”), T(“\n”)).replaceCharacter (T(‘\r’), T(‘\n’))
Ok, that makes sense. I just thought it was a bit odd that when you write a string to a file that it modifies it. (why can’t we all just agree on one newline character?)
It’s not so much a performance issue as a “could be better” one… I don’t like writing code that could be faster
Personally I like the “\r\n” string (don’t hit me) because one means a new line, the other means move to beginning of the line, as it should be. I may just want to move down a line without resetting to the beginning… Old printer codes, so sue me…