将多付款方式结账所拼接的字符串转化成Hashtable

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jokeny_gyh/article/details/84532560

将多付款方式结账所拼接的字符串转化成Hashtable,字符串格式如 21|122;21|;22|12;22|12.2等。

代码如下:

/// <summary>
/// 将多付款方式结账所拼接的字符串转化成Hashtable
/// 字符串格式如 21|122;21|;22|12;22|12.2
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public Hashtable GetPayType(string str)
{
  Hashtable hashtable = new Hashtable();
  string[] s1 = str.Split(';');
  foreach (string s in s1)
  {
    string[] s2 = s.Split('|');
    if (hashtable.Contains(s2[0]))
    {
      hashtable[s2[0]] = Convert.ToDecimal(hashtable[s2[0]]) + Convert.ToDecimal(s2[1] == "" ? "0" : s2[1]);
    }
    else
    {
      hashtable[s2[0]] = s2[1] == "" ? "0" : s2[1];
    }
  }
  return hashtable;
}

猜你喜欢

转载自blog.csdn.net/Jokeny_gyh/article/details/84532560
今日推荐