Wednesday, August 25, 2010

Extract SubString From Delimitered Chars

public string ExtractSubStringFromDelimiterChar(string strValue, char Char1, char Char2)
{
if (string.IsNullOrEmpty(strValue)) {
return strValue;

} else {
Int16 iStart = strValue.IndexOf(Char1);
Int16 iEnd = strValue.LastIndexOf(Char2);

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


}
}

}


VB.Net

Public Function ExtractSubStringFromDelimiterChar(ByVal strValue As String, ByVal Char1 As Char, ByVal Char2 As Char) As String
If String.IsNullOrEmpty(strValue) Then
Return strValue
Else

Dim iStart As Int16 = strValue.IndexOf(Char1)
Dim iEnd As Int16 = strValue.LastIndexOf(Char2)

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