Convert a string?

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

    Convert a string?

    Hello,

    I would like to convert
    string "I am a fish" into a hex string if easy?

    Fairly new to .NET and have looked on google etc without much luck.

    Any help appreciated,

    Gary.
  • Kevin Spencer

    #2
    Re: Convert a string?

    What exactly do you mean by "convert... to a hex string?" Apparently, you are
    referring to a string containing hexadecimal notation, but of what? A string
    is a sequence of Unicode characters, unless it is in some other form of
    encoding. At any rate, perhaps a statement of the purpose of this would
    help.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP

    Help test our new betas,
    DSI PrintManager, Miradyne Component Libraries:


    "G" <g@nospam.comwr ote in message
    news:800BEACB-606F-4F48-8DD9-24EE28B75FC9@mi crosoft.com...
    Hello,
    >
    I would like to convert
    string "I am a fish" into a hex string if easy?
    >
    Fairly new to .NET and have looked on google etc without much luck.
    >
    Any help appreciated,
    >
    Gary.

    Comment

    • PS

      #3
      Re: Convert a string?


      "G" <g@nospam.comwr ote in message
      news:800BEACB-606F-4F48-8DD9-24EE28B75FC9@mi crosoft.com...
      Hello,
      >
      I would like to convert
      string "I am a fish" into a hex string if easy?
      Say it 3 times while facing north at sunset.
      >
      Fairly new to .NET and have looked on google etc without much luck.
      >
      Any help appreciated,
      >
      Gary.

      Comment

      • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

        #4
        RE: Convert a string?

        How about something like this (needs checking since I threw it together
        pretty fast):

        static string Hex(string s)
        {
        byte[] b = System.Text.Enc oding.UTF8.GetB ytes(s);
        string temp="";
        string s2 = "";
        int i;
        for (i = 0; i < b.Length; i++)
        {
        temp = b[i].ToString("x2") ;
        s2+= temp;
        }
        return s2;
        }

        --Peter
        --
        Site: http://www.eggheadcafe.com
        UnBlog: http://petesbloggerama.blogspot.com
        Short urls & more: http://ittyurl.net




        "G" wrote:
        Hello,
        >
        I would like to convert
        string "I am a fish" into a hex string if easy?
        >
        Fairly new to .NET and have looked on google etc without much luck.
        >
        Any help appreciated,
        >
        Gary.

        Comment

        • Mark Rae

          #5
          Re: Convert a string?

          "Peter Bromberg [C# MVP]" <pbromberg@yaho o.yabbadabbadoo .comwrote in
          message news:11F49251-DB91-445C-B1E8-8582AA35CD6C@mi crosoft.com...
          How about something like this (needs checking since I threw it together
          pretty fast):
          Works perfectly...


          Comment

          • Abubakar

            #6
            Re: Convert a string?

            Maybe he wants something like a base64 representation of his string?

            ...ab

            "Kevin Spencer" <unclechutney@n othinks.comwrot e in message
            news:%23rbrMwkY HHA.588@TK2MSFT NGP06.phx.gbl.. .
            What exactly do you mean by "convert... to a hex string?" Apparently, you
            are referring to a string containing hexadecimal notation, but of what? A
            string is a sequence of Unicode characters, unless it is in some other
            form of encoding. At any rate, perhaps a statement of the purpose of this
            would help.
            >
            --
            HTH,
            >
            Kevin Spencer
            Microsoft MVP
            >
            Help test our new betas,
            DSI PrintManager, Miradyne Component Libraries:

            >
            "G" <g@nospam.comwr ote in message
            news:800BEACB-606F-4F48-8DD9-24EE28B75FC9@mi crosoft.com...
            >Hello,
            >>
            >I would like to convert
            >string "I am a fish" into a hex string if easy?
            >>
            >Fairly new to .NET and have looked on google etc without much luck.
            >>
            >Any help appreciated,
            >>
            >Gary.
            >
            >

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: Convert a string?

              Abubakar <emailallrise@y ahoo.comwrote:
              Maybe he wants something like a base64 representation of his string?
              Well, base 64 isn't hex - but the same problem would occur: base64 is a
              way of representing *binary* data as text, so how does the OP want to
              convert the original text to binary in the first place?

              --
              Jon Skeet - <skeet@pobox.co m>
              http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
              If replying to the group, please do not mail me too

              Comment

              Working...