日期:2014-05-18 浏览次数:21268 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; namespace sxLdfang { class Program { static void Main() { string s = "44564941303233322E350D0A44564942303233342E320D0A44564943303232392E360D0A44564F41303232382E310D0A44564F42303232342E350D0A44564F43303232392E310D0A444C4F41303032382E340D0A444C4F42303035302E320D0A444C4F43303033322E360D0A44544D50303034322E300D0A44485A46303035302E300D0A44564254303434302E310D0A4456424E303030302E300D0A44544D42303132302E300D0A4456424C303130302E300D0A"; byte[]buff=new byte[s.Length]; int index=0; for (int i = 0; i < s.Length; i += 2) { buff[index] = Convert.ToByte(s.Substring(i, 2), 16); ++index; } string result = Encoding.Default.GetString(buff); Console.Write(result); } } }
------解决方案--------------------
错了一点,byte数组大小修改一下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; namespace sxLdfang { class Program { static void Main() { string s = "44564941303233322E350D0A44564942303233342E320D0A44564943303232392E360D0A44564F41303232382E310D0A44564F42303232342E350D0A44564F43303232392E310D0A444C4F41303032382E340D0A444C4F42303035302E320D0A444C4F43303033322E360D0A44544D50303034322E300D0A44485A46303035302E300D0A44564254303434302E310D0A4456424E303030302E300D0A44544D42303132302E300D0A4456424C303130302E300D0A"; byte[]buff=new byte[s.Length/2]; int index=0; for (int i = 0; i < s.Length; i += 2) { buff[index] = Convert.ToByte(s.Substring(i, 2), 16); ++index; } string result = Encoding.Default.GetString(buff); Console.Write(result); } } }