Readymade Function to get SubString from a String at character x
public static string GetSubString(string tobeParsed,string beforeorAfter, char charactertoCheck)
{
string resultString = "";
if (string.IsNullOrEmpty(tobeParsed))
{
return resultString;
}
else
{
int indexofChar = tobeParsed.IndexOf(charactertoCheck);
if (beforeorAfter == "before")
{
if (indexofChar==0)
{
resultString = "";
}
else
{
resultString = tobeParsed.Substring(0, indexofChar);
}
}
if (beforeorAfter == "after")
{
if (tobeParsed.Length - 1 == indexofChar)
{
resultString = "";
}
else
{
resultString = tobeParsed.Substring(indexofChar+1,
tobeParsed.Length - (indexofChar+1));
}
}
return resultString;
}
}
0 comments:
Post a Comment