need help with a search then compare then replace string

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Striker1980
Posts: 1
Joined: Tue Oct 13, 2009 9:41 pm
Location: United States

need help with a search then compare then replace string

Post by Striker1980 »

Be warned this may be very confusing.

So I'm very new to textpad and also programming. I've got this data string that has a known structure when all is well. What I'm looking for is a better way to parse the data. Here is what I've done so far:

This is the data I start with:

2303C82303C84303C84303C8210221040005
410241042E140002
2A022A0A48020000000000004802480741654BC641
2A022A0A4502000000000000480248074180BFC441
2A022A0A470200000000000048024807414FF0A441
2A022A0A47020000000000004802480741666B8541
2A022A0A4702000000000000480248074160CCCC41
2A022A0A47020000000000004802480741666B8541
2A022A0A470200000000000048024807414FF0A441
2A022A0A480200000000000048024807415B2E1441
2A022A0A4802000000000000480248074160CCCD41
2A022A0A48020000000000004802480741666B8541
2A022A0A480200000000000048024807414A51EB41
2A022A0A4802000000000000480248074160CCCD41
2A022A0A4802000000000000480248074160CCCD
412A022A0A4802000000000000
480248074160CCCD412A022A0A48020000
0000000048024807415B2E1441
2A022A0A480200000000000048024807417CE666
41

Then I use my macro that breaks down as such:

SHIFT + CTRL + END (select all)
CTRL + J (join lines)
CTRL + HOME (set cursor to home)
F8 (open replace box)

(NEXT LINES ARE REPLACE)

“(1space)“ WITH “(nothing)�
“2303C82303C8� WITH “\n\n2303C8 2303C8 “
“4303C84303C8� WITH “\n\n4303C8 4303C8 “
“210221040005� WITH “\n\n2102 2104 0005 “
“410241042E150002� WITH “\n\n4102 4104 2E15\n\n0002 “
“2A022A0A� WITH “\n\n2A02 2A0A “
“48024807� WITH “\n\n4802 4807 “
“29022906� WITH “\n\n2902 2906 “
“2702272E� WITH “\n\n2702 272E “

then I get:

2303C8 2303C8

4303C8 4303C8

2102 2104 0005

4102 4104 2E14

0002

2A02 2A0A 4802000000000000

4802 4807 41654BC641

2A02 2A0A 4502000000000000

4802 4807 4180BFC441

2A02 2A0A 4702000000000000

4802 4807 414FF0A441

2A02 2A0A 4702000000000000

4802 4807 41666B8541

2A02 2A0A 4702000000000000

4802 4807 4160CCCC41

2A02 2A0A 4702000000000000

4802 4807 41666B8541

2A02 2A0A 4702000000000000

4802 4807 414FF0A441

2A02 2A0A 4802000000000000

4802 4807 415B2E1441

2A02 2A0A 4802000000000000

4802 4807 4160CCCD41

2A02 2A0A 4802000000000000

4802 4807 41666B8541

2A02 2A0A 4802000000000000

4802 4807 414A51EB41

2A02 2A0A 4802000000000000

4802 4807 4160CCCD41

2A02 2A0A 4802000000000000

4802 4807 4160CCCD41

2A02 2A0A 4802000000000000

4802 4807 4160CCCD41

2A02 2A0A 4802000000000000

4802 4807 415B2E1441

2A02 2A0A 4802000000000000

4802 4807 417CE66641

Nice and neat, but it is reliant on the fact that the data never changes. lets use the parsed lines 4 and 5:

4102 4104 2E14

0002

“410241042E150002� WITH “\n\n4102 4104 2E15\n\n0002 “
(this part of the macro is very reliant on all the text remaining exacly the same)
how would you macro a line that could have potential data changes ie:410241042E160002
Can textpad:

search for 4102
Check the next 4 characters are 4104
if yes add 2 lines before 4102
then add a space between 4102 and 4104
then add a space after 4104
skip the next 4 characters
check the characters match 0002

Is there a way
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

No time to dig into this right now, but I suspect that can be done with RegEx. May take more than one pass, but they could be combined with a macro....
Hope this was helpful.............good luck,
Bob
Post Reply