Thank you, this is actually the kind of solution I was looking for, but didn’t knew about the existence of SubString
. And you are right that in my example some whitespaces where cut off.
Still, the regex solution by @AndiMD seems to be ~20% faster and allocates (slightly) less memory.