Is it possible? Given that C # uses immutable strings, one would expect that there would be a method for strings:
var expensive = ReadHugeStringFromAFile();
var cheap = expensive.SharedSubstring(1);
If there is no such function, why worry about strings being immutable? Or, alternatively, if the strings are already immutable for other reasons, why not provide this method?
The specific reason I'm doing this is to parse the files. Simple recursive descent analyzers (such as those created by TinyPG or easily written by hand) use a substring all over the place. This means that if you give them a large file to parse, disabling memory is unbelievable. Of course, there are workarounds - basically roll up your own SubString class, and then, of course, forget about the possibility of using String methods such as StartsWith or String, such as Regex, so you also need to flip your own version. I guess parser generators like ANTLR basically do this, but my format is simple enough to not justify using such a monster. Even TinyPG is probably redundant.
Someone please tell me that I missed some obvious or not so obvious standard C # method call somewhere ...
source
share