/// <summary>
/// 获取源字串(str)里 分隔符(fgf)分割的子字符串,返回分割后的index(0:第一个分隔符的左面的字符串)位置的子字符串
/// </summary>
/// <param name="str"></param>
/// <param name="fgf"></param>
/// <returns></returns>
public string getSubString(string str,string fgf,int index)
{
// 比如获取字符串:"001&高洁&哈哈&嘿嘿" 想获取001 即 & 左面的字符串,此方法只适用取&的左右字符串
try
{
if (str == "" || str == null)
{
MessageBox.Show("你传入的源字符串为空或null", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return "";
}
string[] sArray = Regex.Split(str, fgf, RegexOptions.IgnoreCase);
return sArray[index]; // 返回str里的fgf左面的子字符串
}
catch (Exception e)
{
MessageBox.Show("fengzhuang.dll.Class1.getSubString." + e.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return str; // 出现错误返回源字符串
}
}