1. 程式人生 > >將多付款方式結賬所拼接的字串轉化成Hashtable

將多付款方式結賬所拼接的字串轉化成Hashtable

將多付款方式結賬所拼接的字串轉化成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; }