simple conversion string->bytes->string changes my data???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jazper

    simple conversion string->bytes->string changes my data???

    hi

    can anybody explain that to me:
    i did the following:
    - 1. input of char 244 ("ô") into string
    - 2. convert to getbytes
    - 3. convert back to string

    char 244 changed to char 63 ("?")
    why??? what can i do the get the same string...?

    --- Code -------------------------------
    string str = ((char)244).ToS tring(); //"ô"
    byte[] btVal = System.Text.ASC IIEncoding.ASCI I.GetBytes(str) ;
    string str2 = System.Text.ASC IIEncoding.ASCI I.GetString(btV al);
    --- Code -------------------------------

    regards, jazper




  • Mattias Sjögren

    #2
    Re: simple conversion string->bytes->string changes my data???

    [color=blue]
    >char 244 changed to char 63 ("?")
    >why???[/color]

    244 is not a 7-bit ASCII character. See

    Ever wonder about that mysterious Content-Type tag? You know, the one you’re supposed to put in HTML and you never quite know what it should be? Did you ever get an email from your friends in…





    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    • Jazper

      #3
      Re: simple conversion string->bytes->string changes my data???

      plz dont let me beg and weep...
      how can i solve my problem. (i dont want to read a book about utf-8 to solve
      this little problem) :-)

      so, where can i set the encoding type for GetBytes() and GetString()?

      pleeeeease...
      Jazper.




      "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> schrieb im Newsbeitrag
      news:O2DabkLpDH A.1632@TK2MSFTN GP10.phx.gbl...[color=blue]
      >[color=green]
      > >char 244 changed to char 63 ("?")
      > >why???[/color]
      >
      > 244 is not a 7-bit ASCII character. See
      >
      > http://www.joelonsoftware.com/articles/Unicode.html
      > http://www.yoda.arachsys.com/csharp/unicode.html
      >
      >
      >
      > Mattias
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/
      > Please reply only to the newsgroup.[/color]


      Comment

      • Austin Ehlers

        #4
        Re: simple conversion string-&gt;bytes-&gt;string changes my data???

        Try one of the static Encoding methods:

        string str=((char)244) .ToString();
        byte[] bytes=Encoding. UTF8.GetBytes(s tr);
        string str2=Encoding.U TF8.GetString(b ytes);

        Austin Ehlers

        On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.a.z@bluewin. ch> wrote:
        [color=blue]
        >plz dont let me beg and weep...
        >how can i solve my problem. (i dont want to read a book about utf-8 to solve
        >this little problem) :-)
        >
        >so, where can i set the encoding type for GetBytes() and GetString()?
        >
        >pleeeeease.. .
        >Jazper.
        >
        >
        >
        >
        >"Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> schrieb im Newsbeitrag
        >news:O2DabkLpD HA.1632@TK2MSFT NGP10.phx.gbl.. .[color=green]
        >>[color=darkred]
        >> >char 244 changed to char 63 ("?")
        >> >why???[/color]
        >>
        >> 244 is not a 7-bit ASCII character. See
        >>
        >> http://www.joelonsoftware.com/articles/Unicode.html
        >> http://www.yoda.arachsys.com/csharp/unicode.html
        >>
        >>
        >>
        >> Mattias
        >>
        >> --
        >> Mattias Sjögren [MVP] mattias @ mvps.org
        >> http://www.msjogren.net/dotnet/
        >> Please reply only to the newsgroup.[/color]
        >[/color]

        Comment

        • Jazper

          #5
          Re: simple conversion string-&gt;bytes-&gt;string changes my data???

          cool, thank you for your short solution, austin.
          works fine!
          cheers, jazper


          "Austin Ehlers" <the*remove*bor ed*me*guy16@hot mail.com> wrote in message
          news:kavlqvkob1 kb9d3fq98pcd49c 8spa6s5k1@4ax.c om...[color=blue]
          > Try one of the static Encoding methods:
          >
          > string str=((char)244) .ToString();
          > byte[] bytes=Encoding. UTF8.GetBytes(s tr);
          > string str2=Encoding.U TF8.GetString(b ytes);
          >
          > Austin Ehlers
          >
          > On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.a.z@bluewin. ch> wrote:
          >[color=green]
          > >plz dont let me beg and weep...
          > >how can i solve my problem. (i dont want to read a book about utf-8 to[/color][/color]
          solve[color=blue][color=green]
          > >this little problem) :-)
          > >
          > >so, where can i set the encoding type for GetBytes() and GetString()?
          > >
          > >pleeeeease.. .
          > >Jazper.
          > >
          > >
          > >
          > >
          > >"Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> schrieb im[/color][/color]
          Newsbeitrag[color=blue][color=green]
          > >news:O2DabkLpD HA.1632@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
          > >>
          > >> >char 244 changed to char 63 ("?")
          > >> >why???
          > >>
          > >> 244 is not a 7-bit ASCII character. See
          > >>
          > >> http://www.joelonsoftware.com/articles/Unicode.html
          > >> http://www.yoda.arachsys.com/csharp/unicode.html
          > >>
          > >>
          > >>
          > >> Mattias
          > >>
          > >> --
          > >> Mattias Sjögren [MVP] mattias @ mvps.org
          > >> http://www.msjogren.net/dotnet/
          > >> Please reply only to the newsgroup.[/color]
          > >[/color]
          >[/color]


          Comment

          • Jazper

            #6
            Re: simple conversion string-&gt;bytes-&gt;string changes my data???

            cool, thank you for your short solution, austin.
            works fine!
            cheers, jazper


            "Austin Ehlers" <the*remove*bor ed*me*guy16@hot mail.com> wrote in message
            news:kavlqvkob1 kb9d3fq98pcd49c 8spa6s5k1@4ax.c om...[color=blue]
            > Try one of the static Encoding methods:
            >
            > string str=((char)244) .ToString();
            > byte[] bytes=Encoding. UTF8.GetBytes(s tr);
            > string str2=Encoding.U TF8.GetString(b ytes);
            >
            > Austin Ehlers
            >
            > On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.a.z@bluewin. ch> wrote:
            >[color=green]
            > >plz dont let me beg and weep...
            > >how can i solve my problem. (i dont want to read a book about utf-8 to[/color][/color]
            solve[color=blue][color=green]
            > >this little problem) :-)
            > >
            > >so, where can i set the encoding type for GetBytes() and GetString()?
            > >
            > >pleeeeease.. .
            > >Jazper.
            > >
            > >
            > >
            > >
            > >"Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> schrieb im[/color][/color]
            Newsbeitrag[color=blue][color=green]
            > >news:O2DabkLpD HA.1632@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
            > >>
            > >> >char 244 changed to char 63 ("?")
            > >> >why???
            > >>
            > >> 244 is not a 7-bit ASCII character. See
            > >>
            > >> http://www.joelonsoftware.com/articles/Unicode.html
            > >> http://www.yoda.arachsys.com/csharp/unicode.html
            > >>
            > >>
            > >>
            > >> Mattias
            > >>
            > >> --
            > >> Mattias Sjögren [MVP] mattias @ mvps.org
            > >> http://www.msjogren.net/dotnet/
            > >> Please reply only to the newsgroup.[/color]
            > >[/color]
            >[/color]


            Comment

            Working...