Here i am writing into a text file..I am searching for a key word Raiserror in a sql file and if that keyword exist i have to write that line..
It is writing like
LineNo : 66 : raiserror ('Sequence number cannot be blank',16,1)
But i need to write only
LineNo : 66 : Sequence number cannot be blank
Is this possible..If so how to trim.. Here is my code
while ((line = file.ReadLine()) != null)
{
if (line.IndexOf("Raiseerror", StringComparison.CurrentCultureIgnoreCase) != -1)
{
dest.WriteLine("LineNo : " + counter.ToString() + " : " + " " + line.TrimStart());
}
counter++;
}
file.BaseStream.Seek(0, SeekOrigin.Begin);
counter = 1;
Any Suggestion?
Try to use this
int errorIndex = line.IndexOf("Raiseerror", StringComparison.CurrentCultureIgnoreCase)
if (errorIndex != -1)
{
int start = line.IndexOf('\'', errorIndex) + 1;
int finish = line.IndexOf('\'', start);
dest.WriteLine("LineNo : " + counter.ToString() + " : " + " " + line.Substring(start,finish - start));
}
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