Author Topic: I can use some help with a macro that adds 0x to every other char  (Read 3288 times)

Ecali1960

  • New Community Member
  • Posts: 2
  • Hero Points: 0
Hi,
I am trying to program a macro that will add a 0x to every other character in a text file. Actually it's an XML file but it's the same thing.
so I have text that looks like this
    050003d4 00000000 000003c8
    54a2 0b33
    543e 0007
    71e4 0c00
    71dc 0000
    5002 029c
    501c 0f00
    502b 0002 0040 0006
    503e 0001
    5018 fd9a
    501f 0006 0000 0001 0100 0002 0080 0000
and would like to make it look like this
    0x05, 0x00, 0x03, 0xd4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc8,
    0x54, 0xa2, 0x0b, 0x33,
    0x54, 0x3e, 0x00, 0x07,
    0x71, 0xe4, 0x0c, 0x00,
    0x71, 0xdc, 0x00, 0x00,
    0x50, 0x02, 0x02, 0x9c,
    0x50, 0x1c, 0x0f, 0x00,
    0x50, 0x2b, 0x00, 0x02, 0x00, 0x40, 0x00, 0x06,
    0x50, 0x3e, 0x00, 0x01,
    0x50, 0x18, 0xfd, 0x9a,
    0x50, 0x1f, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x80, 0x00, 0x00,
I have created a macro that does that but the file is huge and it's many keyboard presses of ctrl+F12.

#include "slick.sh"
_command add0x() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
    _macro('R',1);
    keyin("0x");
    cursor_right(2);
    keyin(",");
    last_event(name2event(' '));c_space();
}

Thank You,
Ed





 

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: I can use some help with a macro that adds 0x to every other char
« Reply #1 on: November 22, 2019, 08:34:11 PM »
You can actually do this with a regular expression.  Go to Search>Replace.  In the Search for box type {[0-9a-f][0-9a-f]} and in the Replace with dialog type 0x#0,.  Then click "Use" and select Regular expression (SlickEdit).

Ecali1960

  • New Community Member
  • Posts: 2
  • Hero Points: 0
Re: I can use some help with a macro that adds 0x to every other char
« Reply #2 on: November 23, 2019, 01:52:44 PM »
Thank you that Worked.
been using slickedit for years but only use the basics
so it's time to start using it's full potential
Again, Thank You!
-Ed

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: I can use some help with a macro that adds 0x to every other char
« Reply #3 on: November 25, 2019, 11:14:23 AM »
Glad to help.