Pages

Wednesday 4 January 2012

Get the value between two strings in c#.net


Here I will explain find to get the value between two strings in c#.net

private static string result;
string st = @"<err:Description>Ship web service is currently unavailable sdfsssssssssssssss.</err:Description></err:PrimaryErrorCode></err:ErrorDetail></err:Errors>";
string findfrom = "<err:Description>";
string findto = "</err:Description>";
string orival = betweenval(st, findfrom, findto);

private static string betweenval(string src, string findfrom, string findto)
{
int start = src.IndexOf(findfrom);
int to = src.IndexOf(findto, start + findfrom.Length);
if (start < 0 || to < 0)
    return "";
else
    result = src.Substring(start + findfrom.Length, to - start - findfrom.Length);
return result;
}






No comments:

Post a Comment