Deleting following spaces in current line

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
HansemannX
Posts: 2
Joined: Fri Jan 25, 2008 7:25 am
Location: Germany

Deleting following spaces in current line

Post by HansemannX »

I have to replace BLANKS in an XML-content. The XML-File looks like this:

...
<element id="zlnr">T0379885</element>
</datarow>
<dataset id="tbl_ZM_tabelle">
<datarow>
<element id="knre1">AT</element>
<element id="knre2">U 14291808</element>
<element id="dreieck">false</element>
<element id="betrag">986</element>
</datarow>
<datarow>
<element id="knre1">GB</element>
<element id="knre2"> 615 5511 59</element>
<element id="dreieck">false</element>
<element id="betrag">254</element>
</datarow>
<datarow>
<element id="knre1">NL</element>
<element id="knre2">812 915422 B01</element>
...

In all lines with the element "knre2" the BLANKS in the following content should be deleted. I tried to use the following macro:

Start Recording:
- Key: F5 -> Find "knre2"
- Key: Strg G -> Goto Column39 (with extend selection)
- Key: F8 -> Replace [:BLANK:] with nothing (Scope: Selected text)
- Key: ESC
- Key: Arrow down
- Key: Pos1
Stop Recording

During recording this works fine, but when playing back the cursor moves correct, but no changes are made.
Perhaps it would be better to use regular expressions, but how ?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

That won't have worked either while recording the macro or while playing it back. The regular expression for a white space character is [[:blank:]], not [:blank:]. (Look in TextPad's help under Reference Information | Regular Expressions | Character Class Operators.) With that correction, your macro works.

You can't do this with a single repeated regular expression replacement. After each replacement, the cursor moves beyond the replaced text, and the context that should restrict the next search has now passed.

But, if your source isn't too long, you can perform this repetitive replacement repeatedly until it beeps:
Find what: (<element id="knre2">.*)[[:blank:]](.*</element>)
Replace with: \1\2

[X] Regular expression

Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
HansemannX
Posts: 2
Joined: Fri Jan 25, 2008 7:25 am
Location: Germany

Post by HansemannX »

:lol: Many thanks for your quick response, ben.

With your help and an upgrade to version 5.1 German the macro works fine.

But there has been another issue. With an old english 5.0 release even the correct macro didn´t work, when playing back.
Post Reply