Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 2days........how to decoder

2days........how to decoder

Scheduled Pinned Locked Moved C#
tutorialquestion
14 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R rainfeet

    using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
    "; } }

    G Offline
    G Offline
    Guffa
    wrote on last edited by
    #3

    How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.

    --- b { font-weight: normal; }

    R L 2 Replies Last reply
    0
    • R rainfeet

      using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
      "; } }

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #4

      rainfeet wrote:

      file_context += temp_string + " ";

      Either do:

      file_context += temp_string + @"
      ";

      -or-

      file_context += temp_string + Environment.NewLine;

      **

      xacc.ide-0.2.0.50 - now with partial MSBuild support!

      **

      R 1 Reply Last reply
      0
      • G Guffa

        How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.

        --- b { font-weight: normal; }

        R Offline
        R Offline
        rainfeet
        wrote on last edited by
        #5

        the source txt file is encodeing with ASCII i want to display it...with Unicode not ASCII(98 97 25 20....)

        G 1 Reply Last reply
        0
        • G Guffa

          How to do what? If I venture to do a guess, you are trying to read a file using a specific encoding? Then you just have to specify the encoding when you create the StreamReader. You don't have to use Peek. Just use ReadLine until it returns null.

          --- b { font-weight: normal; }

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #6

          The 'guess' is on ;P

          **

          xacc.ide-0.2.0.50 - now with partial MSBuild support!

          **

          R 2 Replies Last reply
          0
          • L leppie

            rainfeet wrote:

            file_context += temp_string + " ";

            Either do:

            file_context += temp_string + @"
            ";

            -or-

            file_context += temp_string + Environment.NewLine;

            **

            xacc.ide-0.2.0.50 - now with partial MSBuild support!

            **

            R Offline
            R Offline
            rainfeet
            wrote on last edited by
            #7

            3Q:)

            1 Reply Last reply
            0
            • L leppie

              The 'guess' is on ;P

              **

              xacc.ide-0.2.0.50 - now with partial MSBuild support!

              **

              R Offline
              R Offline
              rainfeet
              wrote on last edited by
              #8

              the source file(.txt) is encoding with ASCII i need read this file and display it in a web page:confused:

              1 Reply Last reply
              0
              • L leppie

                The 'guess' is on ;P

                **

                xacc.ide-0.2.0.50 - now with partial MSBuild support!

                **

                R Offline
                R Offline
                rainfeet
                wrote on last edited by
                #9

                634768511 601989262 ˵(2005-07-09 18:42:55)׶Ϊ˱֤MM˵İȫ뱣ܡ鿴QQ502278472ĸ֪ô 634768511 601989262 ˵(2005-07-09 18:42:55)׶Ϊ˱֤MM˵İȫ뱣ܡ鿴QQ502278472ĸ֪ô now i see this,see??

                1 Reply Last reply
                0
                • R rainfeet

                  the source txt file is encodeing with ASCII i want to display it...with Unicode not ASCII(98 97 25 20....)

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #10

                  Then specify the ASCII encoding when you open the StreamReader.

                  --- b { font-weight: normal; }

                  R 1 Reply Last reply
                  0
                  • R rainfeet

                    using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path)) { //没有到达文件结尾时一直读取文件 while(sr.Peek() > 0) { //读出一行文本 string temp_string = sr.ReadLine(); //进行编码转换,原ASCI码转换成Unicode编码 Here how to do? I tried two days but no good^^ //连接到输出文件内容中 file_context += temp_string + "
                    "; } }

                    F Offline
                    F Offline
                    fang_eric
                    wrote on last edited by
                    #11

                    there are two ways to slove this problem. first is that after you read the bytes,then you convert it to unicode : string temp_string = sr.ReadLine(); // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding unicode = Encoding.Unicode; // Convert the string into a byte[]. byte[] assciiBytes = unicode.GetBytes(temp_string ); // Perform the conversion from one encoding to the other. byte[] unicodeBytes = Encoding.Convert(unicode, ascii, assciiBytes ); the second is that initalize the StreamReader with unicode: using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path, Encoding.Unicode)) { } Just do it!

                    R 1 Reply Last reply
                    0
                    • G Guffa

                      Then specify the ASCII encoding when you open the StreamReader.

                      --- b { font-weight: normal; }

                      R Offline
                      R Offline
                      rainfeet
                      wrote on last edited by
                      #12

                      Then specify the ASCII encoding when you open the StreamReader. how to do this? sr.CurrentEncoding??

                      G 1 Reply Last reply
                      0
                      • F fang_eric

                        there are two ways to slove this problem. first is that after you read the bytes,then you convert it to unicode : string temp_string = sr.ReadLine(); // Create two different encodings. Encoding ascii = Encoding.ASCII; Encoding unicode = Encoding.Unicode; // Convert the string into a byte[]. byte[] assciiBytes = unicode.GetBytes(temp_string ); // Perform the conversion from one encoding to the other. byte[] unicodeBytes = Encoding.Convert(unicode, ascii, assciiBytes ); the second is that initalize the StreamReader with unicode: using(System.IO.StreamReader sr = new System.IO.StreamReader(temp_path, Encoding.Unicode)) { } Just do it!

                        R Offline
                        R Offline
                        rainfeet
                        wrote on last edited by
                        #13

                        i am sorry to tell you 634768511 ?? 601989262 ??(2005-07-09 18:42:55)???????????????????????????????????? i see this

                        1 Reply Last reply
                        0
                        • R rainfeet

                          Then specify the ASCII encoding when you open the StreamReader. how to do this? sr.CurrentEncoding??

                          G Offline
                          G Offline
                          Guffa
                          wrote on last edited by
                          #14

                          new System.IO.StreamReader(temp_path, Encoding.ASCII)

                          --- b { font-weight: normal; }

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups