• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    asp.net 字符串、二進制、編碼數組轉換函數

    來源:懂視網 責編:小采 時間:2020-11-27 22:43:32
    文檔

    asp.net 字符串、二進制、編碼數組轉換函數

    asp.net 字符串、二進制、編碼數組轉換函數:1.字符串轉二進制數組 string content=這是做個測試!; System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); byte[] byteArr = converter.GetBytes(content); 2.二進制數組轉為字符串
    推薦度:
    導讀asp.net 字符串、二進制、編碼數組轉換函數:1.字符串轉二進制數組 string content=這是做個測試!; System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); byte[] byteArr = converter.GetBytes(content); 2.二進制數組轉為字符串

    1.字符串轉二進制數組
    string content="這是做個測試!";

    System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
    byte[] byteArr = converter.GetBytes(content);

    2.二進制數組轉為字符串
    代碼如下:


    System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
    string spcontent = converter.GetString(byteArr );

    在編程中會遇到將文件以二進制數據保存到數據庫的情況,以將"C:\test.html"文件保存到數據庫和讀取出來為例:

    1.將文件以流的形式保存到數據庫中:
    代碼如下:


    int itag=0;

          string content = "";

          StringBuilder sb = new StringBuilder();

           string fileName = @"c:\test.html";
    StreamReader objReader = new StreamReader(fileName, System.Text.Encoding.GetEncoding("gb2312"));
    string sLine = "";
    while (sLine != null)
       {
       sLine = objReader.ReadLine();
      if (sLine != null)
      {//這里可以做相應的處理,如過濾文件中的數據
       sb.Append(sLine);

       }
     }

    objReader.Close();

    content= sb.ToString(); //如果你要將整個文件的內容顯示在界面上,你可以用<%=content%>放到相應的地方

          System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
          byte[] byteArr = converter.GetBytes(content);

    //下面為插入到數據庫代碼,

    strInsertCmd = "insert into Document (DocumentID,DocumentContent,addtime,MODITIME,status) values ('" + DocumentID + "',?,'" + NOWTIME + "','" + NOWTIME + "',' 00 ')";
    cmd=new OleDbCommand(strInsertCm,ConnectionOBJ);
    param = new OleDbParameter("DocumentContent", OleDbType.VarBinary, byteArr.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, byteArr);
    cmd.Parameters.Add(param);
    itag=cmd.ExecuteNonQuery();

    if(itag>0){//成功!}

    2.從數據庫中讀取保存為文件或者字符串和步驟1是一個相反的過程


    1.將GB2312數據轉換為UTF-8數據如下(其他的編碼類推):
    代碼如下:


    public string GB2312ToUTF8(string sSourse) {
    string Utf8_info = string.Empty;
    Encoding utf8 = Encoding.UTF8;
    Encoding gb2312 = Encoding.GetEncoding("gb2312");
    byte[] unicodeBytes = gb2312.GetBytes(sSourse);
    byte[] asciiBytes = Encoding.Convert(gb2312, utf8, unicodeBytes);
    char[] asciiChars = new char[utf8.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
    utf8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
    Utf8_info = new string(asciiChars);
    return Utf8_info;
    }

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    asp.net 字符串、二進制、編碼數組轉換函數

    asp.net 字符串、二進制、編碼數組轉換函數:1.字符串轉二進制數組 string content=這是做個測試!; System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); byte[] byteArr = converter.GetBytes(content); 2.二進制數組轉為字符串
    推薦度:
    標簽: 轉換 net 函數
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 精品国产福利盛宴在线观看| 欧美日韩在线精品一区二区三区激情综合 | 国产高清在线精品一区小说| 久久精品一本到99热免费| 人妻VA精品VA欧美VA| 91久久精品无码一区二区毛片| 国产l精品国产亚洲区在线观看| 日韩亚洲精品福利| 精品国产高清在线拍| 亚洲欧美日韩精品永久在线| 大伊香蕉精品一区视频在线| 人人妻人人澡人人爽人人精品97 | 久久91综合国产91久久精品| 久久精品99久久香蕉国产色戒| 中文国产成人精品久久不卡| 日韩精品免费一线在线观看| 精品国产国产综合精品| 精品第一国产综合精品蜜芽| 国产午夜精品一本在线观看| 亚洲精品欧美综合| 在线观看91精品国产入口| 九九热在线视频观看这里只有精品| 99精品一区二区三区无码吞精| 国内精品久久久人妻中文字幕| 久久99精品久久久久久动态图| 欧美午夜精品久久久久免费视| 少妇人妻偷人精品无码视频新浪| 无码精品人妻一区二区三区中| 日韩av无码久久精品免费| 日韩精品无码一区二区中文字幕| 日韩精品一区二区三区色欲AV| 蜜臀久久99精品久久久久久小说| 日韩精品人妻系列无码专区免费| 久久精品蜜芽亚洲国产AV| 精品人妻人人做人人爽| 国产精品亚洲一区二区三区在线| 国产成人无码久久久精品一| 国产成人精品久久二区二区| 欧美视频精品一区二区三区| 国产精品免费观看视频| 欧美成人精品欧美一级乱黄一区二区精品在线 |