Fastest way to change all items in a nested list
Hi all,
So atm I serializing following json string into a list:
What would the fastest way be to change all category string to lower case? I'm using a nested for loop now after serialization.
Best regards!
4 Replies
Unless you're willing to make your own json serialization code form scratch, not much you can do besides reading and rewriting the whole thing. Newtonsoft json, you can skip part of the process by making a custom converter that parses the json to a json array, get the tokens you want, modifiy then and convert back into tokens before reserializing the whole thing
is the goal just to rewrite the file?
in that case Regex.Replace
or actually
just string.Replace
Could be done with regex but not easily and you have no guaranteed if the file is intended or inline
Hi there, regex was an option. The jsonstring will always be single line. However not sure there is much performance gain using regex over for loops.
I just don’t like to see nested for loops, but in machine code for loops are actually pretty fast, so this might just be the best solution. Thanks!