字符的类型变换

  public class GF_Convert     {         ///          /// 字符串 改换 char数组         ///          ///          ///          /// < http://www.360123.info/linked/20130426.do returns>         public static char[] string2chararray(string in_str, int in_len)         {             char[] ch = new char[in_len];             in_str.ToCharArray().CopyTo(ch, 0);             return ch;         }           ///          /// char数组 改换 字符串         ///          ///          ///                 public static string chararray2string(char[] in_str)         {             string out_str;             out_str = new string(in_str);             int i = out_str.IndexOf('\0', 0);             if (i == -1)                 i = 16;             return out_str.Substring(0, i);         }           ///          /// byte数组 改换 字符串         ///          ///          ///          public static string bytearray2string(byte[] in_str)         {             string out_str;             out_str = System.Text.Encoding.Default.GetString(in_str);             return out_str.Substring(0, out_str.IndexOf('\0', 0));           }           ///          /// 字符串 改换 byte数组  注重改换出来会使正本的bytearray长度变短         ///          ///          ///          public static byte[] string2bytearray(string in_str)         {             return System.Text.Encoding.Default.GetBytes(in_str);         }           ///          /// 字符串 改换 byte数组  长度为传如的长度         ///          /// 传入字符串         /// 政策字节数组长度         ///          public static byte[] string2bytearray(string in_str, int iLen)         {             byte[] bytes = new byte[iLen];             byte[] bsources=System.Text.Encoding.Default.GetBytes(in_str);             Array.Copy(bsources, bytes, bsources.Length);                                       return bytes;         }                  ///          /// 将字符串编码为Base64字符串         ///          ///          ///          public static string Base64Encode(string str)         {             byte[] barray;             barray = Encoding.Default.GetBytes(str);             return Convert.ToBase64String(barray);         }           ///          /// 将Base64字符串解码为通常字符串         ///          ///          ///          public static string Base64Decode(string str)         {             byte[] barray;             try             {                 barray = Convert.FromBase64String(str);                 return Encoding.Default.GetString(barray);             }             catch             {                 return str;             }         }           ///          /// 图画 改换 byte数组         ///          ///          ///          ///          public static byte[] image_Image2Byte(Image pic, System.Drawing.Imaging.ImageFormat fmt)         {             MemoryStream mem = new MemoryStream();             pic.Save(mem, fmt);             mem.Flush();             return mem.ToArray();         }         ///          /// byte数组 改换 图画         ///          ///          ///          public static Image image_Byte2Image(byte[] bytes)         {             MemoryStream mem = new MemoryStream(bytes, true);             mem.Read(bytes, 0, bytes.Length);             mem.Flush();             Image aa = Image.FromStream(mem);             return aa;         }                          ///          /// ip 改换 长整形         ///          ///          ///          public static long IP2Long(string strIP)         {               long[] ip = new long[4];               string[] s = strIP.Split('.');             ip[0] = long.Parse(s[0]);             ip[1] = long.Parse(s[1]);             ip[2] = long.Parse(s[2]);             ip[3] = long.Parse(s[3]);               return (ip[0] << 24)   (ip[1] << 16)   (ip[2] << 8)   ip[3];         }           ///          /// 长整形 改换 IP         ///          ///          ///          public static string Long2IP(long longIP)         {                 StringBuilder sb = new StringBuilder("");             sb.Append(longIP >> 24);             sb.Append(".");               //将高8方位0,然后右移16为                 sb.Append((longIP  http://www.qingdao2000.com/linked/20130426.do 
posted @ 2013-04-27 02:40  chinadiy197601  阅读(246)  评论(0编辑  收藏  举报