I have a large SQL Server insert script
INSERT [dbo].[Table] ([Key], [Name], [Value], [Module])
VALUES (1, N'Product', N'Value 1', N'Value 2')
Now I need to parse this large file, line by line and for each value that is NVARCHAR N'VALUEHERE' I want to replace it with some custom info I fetch from a database.
If this is my script:
INSERT [dbo].[Table] ([Key], [Name], [Value], [Module])
VALUES (1, N'Product', N'Value 1', N'Value 2')
After I parse it I want to update it to:
INSERT [dbo].[Table] ([Key], [Name], [Value], [Module])
VALUES (1, N'Product Changed', N'Value 1 with some custom info', N'Value 2 with different info')
Of course the real scenario is a bit different.
In big, I want to fetch all nvarchar values and for each value that starts with N' get that value from single quotes, do some operation on it and update it with the new value, then move to next N' and so on.
My question:
How can I fetch every single value between quotes N'VALUE' change that value and replace with the new value N'CHANGED'?
string line = null;
StreamReader file = new System.IO.StreamReader(@"c:\script.sql");
while((line = file.ReadLine()) != null)
{
// work with `line` here to get each value
}
One more issue, how do I fetch the value if it's something like:
`N'Jimm''s device is broken'`