Wednesday, August 25, 2010

Extract SubString From the Delimitered String

public string ExtractSubStringFromDelimiterString(string strValue, string s1, string s2)
{
if (string.IsNullOrEmpty(strValue)) {
return strValue;

} else {
Int16 iStart = strValue.IndexOf(s1);
Int16 iEnd = strValue.LastIndexOf(s2);

if ((iStart >= 0 & iEnd > iStart)) {
return strValue.Substring(iStart + 1, (iEnd) - (iStart + 1));
} else {
return strValue;


}
}

}


VB.Net

Public Function ExtractSubStringFromDelimiterString(ByVal strValue As String, ByVal s1 As String, ByVal s2 As String) As String
If String.IsNullOrEmpty(strValue) Then
Return strValue
Else

Dim iStart As Int16 = strValue.IndexOf(s1)
Dim iEnd As Int16 = strValue.LastIndexOf(s2)

If (iStart >= 0 And iEnd > iStart) Then
Return strValue.Substring(iStart + 1, (iEnd) - (iStart + 1))
Else
Return strValue


End If
End If

End Function

No comments:

Post a Comment

 
Locations of visitors to this page