Powered By Blogger

Monday, October 26, 2009

split, substring and remove null values in string array in c#

public string[] MySplit(string SplitStr,string SplitbyStr)
{
Sltstr = SplitStr.Split((SplitbyStr).ToCharArray());
return Sltstr;
}

public string MySubString(string Mystr, int cnt)
{
MyInt = Mystr.Length;
if (cnt > MyInt)
{
MyTemp = Mystr.Substring(0, MyInt);
}
else
{
MyTemp = Mystr.Substring(0, cnt);
}
return MyTemp;
}

public string[] RemoveEmptyFromArray(string[] OriginalArray)
{

SB.Remove(0, SB.Length);
//IEnumerator IEnu = MySplit(OriginalArray[0],":") .GetEnumerator();
//while (IEnu.MoveNext())
//{
// if (IEnu.Current.ToString() != "")
// {
// sTmp.Append(IEnu.Current.ToString()+ "||");
// }
//}
for (int i = 0; i < OriginalArray.Length; i++)
{
string s = Convert.ToString(OriginalArray[i]);
//if (i == 0 && s != "")
// if (s == "")
if (i == 0 && s != null)
{
SB.Append(Convert.ToString(s));
}
else if (Convert.ToString(SB) == "" && s != null)
{
SB.Append(Convert.ToString(s));
}
else if (s != null)
{
SB.Append("|" + Convert.ToString(s));
}


//if (Convert.ToString(OriginalArray[i]) != "")
//{
// if (i == OriginalArray.Length - 1)
// {
// SB.Append(Convert.ToString(OriginalArray[i]));
// }
// else
// {
// SB.Append(Convert.ToString(OriginalArray[i]) + "|");
// }
//}

}
return MySplit(SB.ToString(), "|");



}

No comments:

Post a Comment