help in program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trixxy
    New Member
    • Sep 2008
    • 26

    help in program

    hello i'm doing a hex to ascii converter. but now the problem is whenever it's converted, the hex code would be in front of the ASCII code.

    private void convertButton_C lick(object sender, EventArgs e)
    {
    asciiTextBox.Te xt = HexString2Ascii (hexTextBox.Tex t);
    }

    Input: 4153434949
    Output: 4153434949ASCII



    i know the problem lies with the hexTextBox.Text . but how do i remove the 4153434949 in front of the converted one?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What is the definition of the function HexString2Ascii ?

    Comment

    • trixxy
      New Member
      • Sep 2008
      • 26

      #3
      Originally posted by Banfa
      What is the definition of the function HexString2Ascii ?
      Code:
      private string HexString2Ascii(string HexString)
              {
                  StringBuilder Sb = new StringBuilder(hexTextBox.Text);
                  for (int intI = 0; intI <= hexTextBox.Text.Length - 2; intI += 2)
                  {
                      Sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(HexString.Substring(intI, 2), System.Globalization.NumberStyles.HexNumber))));
                  }
                  return Sb.ToString();
              }
      Last edited by Banfa; Oct 17 '08, 09:16 AM. Reason: Added [Code]...[/code] tags

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Can you explain the purpose of line 3?

        Comment

        • trixxy
          New Member
          • Sep 2008
          • 26

          #5
          Originally posted by Banfa
          Can you explain the purpose of line 3?
          changes the text into a string.

          Comment

          • newb16
            Contributor
            • Jul 2008
            • 687

            #6
            Looks like java to me.

            Comment

            • trixxy
              New Member
              • Sep 2008
              • 26

              #7
              Originally posted by newb16
              Looks like java to me.
              yeah c# is like java. object oriented.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by newb16
                Looks like java to me.
                I think it is C# and indeed the original text is stored in that StringBuilder first and
                next the ASCII characters are appended do it. Line #3 should instantiate an
                empty StringBuilder instead.

                kind regards,

                Jos

                Comment

                • trixxy
                  New Member
                  • Sep 2008
                  • 26

                  #9
                  Originally posted by JosAH
                  I think it is C# and indeed the original text is stored in that StringBuilder first and
                  next the ASCII characters are appended do it. Line #3 should instantiate an
                  empty StringBuilder instead.

                  kind regards,

                  Jos
                  AH. thanks a whole lot dude. that made the trick.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by trixxy
                    AH. thanks a whole lot dude. that made the trick.
                    You're welcome but next time make sure you post your C# questions in the .NET forum.
                    This is a C and C++ forum and has (almost) nothing to do with C# (nor Java).

                    kind regards,

                    Jos (moderator)

                    Comment

                    Working...