I have a SQL script that I need to run using my .NET app. The script contains various commands separated by "GO". To separate the commands, I am using the Split() function:
var sqlqueries = Script.Split(new[] { " GO ", "GO" }, StringSplitOptions.RemoveEmptyEntries);
The problem is that my scripts contain columns and tables with the word "CATEGORY" in them.
Is there any way to add exceptions to the .Split function? If not, what are my options? (I've seen Regex, but have no idea how to use it)
You may split on GO separated by word boundaries:
var sqlqueries = Regex.Split(Script, @"\bGO\b");
Note that this might generate an empty extra final entry in the output array, assuming your final query ends with GO, but does not have another query after it. But, this can easily enough be dealt with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With