Paste ASCII HEX with conversion to ASCII

Paste ASCII HEX with conversion to ASCII

2
NewbieNewbie
2

    Jun 04, 2008#1

    I'd like to paste hex values into UltraEdit, so that they end up as ANSI text.

    F.e. the buffer contains:
    30:30:31:

    I'd like to paste into UltraEdit;
    001

    Using UltraEdit 14.00b

    TIA,
    Wessel

    6,682583
    Grand MasterGrand Master
    6,682583

      Jun 04, 2008#2

      That's a conversion, not a simple paste. Therefore you need a macro or script which pastes first your ASCII presented hex data into a file and then runs replaces to replace them with the ASCII characters. For example with a macro it would be:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      NewFile
      Paste
      Top
      Find "20:"
      Replace All " "
      Find "21:"
      Replace All "!"
      and so on for all other ASCII characters according to View - ASCII Table except 30-3A and 41-46 which must be at end of the macro.
      Find "7D:"
      Replace All "}"
      Find "7E:"
      Replace All "~"
      Find "30:"
      Replace All "#!0!#"
      Find "31:"
      Replace All "#!1!#"
      Find "32:"
      Replace All "#!2!#"
      Find "33:"
      Replace All "#!3!#"
      Find "34:"
      Replace All "#!4!#"
      Find "35:"
      Replace All "#!5!#"
      Find "36:"
      Replace All "#!6!#"
      Find "37:"
      Replace All "#!7!#"
      Find "38:"
      Replace All "#!8!#"
      Find "39:"
      Replace All "#!9!#"
      Find "41:"
      Replace All "#!A!#"
      Find "42:"
      Replace All "#!B!#"
      Find "43:"
      Replace All "#!C!#"
      Find "44:"
      Replace All "#!D!#"
      Find "45:"
      Replace All "#!E!#"
      Find "46:"
      Replace All "#!F!#"
      Find "3A:"
      Replace All ":"
      Find MatchCase RegExp "'#!^([0-9A-F]^)!#"
      Replace All "^1"

      The macro property Continue if search string not found must be checked for this macro. Add UnixReOn or PerlReOn at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
      Best regards from an UC/UE/UES for Windows user from Austria

      262
      MasterMaster
      262

        Jun 04, 2008#3

        And here is a script to do the same. Assign it a short cut key and it is pretty fast to paste-convert-hex-into-ascii. (Not testet for UTF8/Unicode files).

        Code: Select all

        var line = UltraEdit.activeDocument.currentLineNum; /* remember where to insert */
        var col  = UltraEdit.activeDocument.currentColumnNum; /* remember where to insert */
        if (typeof(UltraEdit.activeDocumentIdx) == "undefined") col++;
        UltraEdit.activeDocument.top(); /* go to top and paste hex eg. 30:30:31: */
        UltraEdit.activeDocument.paste(); /* paste clipboard contents */
        UltraEdit.activeDocument.selectToTop(); /* select it */
        
        var oStr = ""; /* outputvariable */
        
        if (UltraEdit.activeDocument.isSel()) { /* is anything selected ? */
          var isThisHex = UltraEdit.activeDocument.selection; /* get selected text */
          isThisHex = isThisHex.replace(/:/g,""); /* remove semicolons: Before: 30:30:31: After: 303031 */
        
          try {
           for (j=0;j<isThisHex.length;j=j+2) { /* iterate jumping 2 positions in each loop */
              var iChr = isThisHex.substr(j,2); /* read a single hex escaped character */
        
              if(iChr=="00") { /* hex 00 is suppressed as blank */
                 iChr="20"; /* hex 20 = blank */
              }
        
              // Un-escape two character hex into single character
              oStr = oStr + String.fromCharCode(parseInt( iChr, 16 ));
           }
          }
          catch (conversionError) {
            /* do nothing if it can't be converted - Insert your own error handling */
          }
        }
        UltraEdit.activeDocument.deleteText(); /* delete pasted contents after it is retrieved */
        UltraEdit.activeDocument.gotoLine(line,col); /* go to original position in document */
        UltraEdit.activeDocument.write(oStr); /* write converted string */

        2
        NewbieNewbie
        2

          Jun 04, 2008#4

          First assumed script worked on selected text, but it works on the clipboard :) Great.

          Thanks a bunch,
          Wessel