Highlighting fixed positions within a string.

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
Blackat
Posts: 2
Joined: Wed Dec 30, 2009 11:30 am

Highlighting fixed positions within a string.

Post by Blackat »

I have an issue where I have to break down strings a lot in different parts..

For example:
@A B21091130170000000000000001
@A B11091202163000000000000001

@A is a part
B* is a part
091113 is yymmdd
etc ..

What i would like is to have color highlighting on the different parts (that are always at the same position)

So it would show somthing like this the string like this.
position 1,2 (blue)
position 4,5 (red)
Position 7-13 (green) etc..

@A B11091202163000000000000001

Is this feasible with the current syntax highlighting?
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Sorry, the answer is NO. The current syntax highlighting tools cannot do that.

But you could use RegEx to install space chars at certain fixed points so that you get something like this:

@A B2 1091130 1700 000000000 00001
@A B1 1091202 1630 000000000 00001
Hope this was helpful.............good luck,
Bob
Blackat
Posts: 2
Joined: Wed Dec 30, 2009 11:30 am

Post by Blackat »

While that is a nice idea for splitting up some parts the issue is that spaces can be a "valid" entry of a specific spot.. and might become a bit confusing.

thank you for the comment however :)

propably will end up using excell, but it is a shame cause this requires manual input, while recongnition of the appropriate file type would have been ideal.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

If the positions are fixed positions, then the space chars will be included and will not be a problem. Instead of inserting spaces, you could insert other chars, like a period or an underscore

Example using period, space,underscore,hyphen, and tilde as visual delimiters, using your example:
@A B21091130170000000000000001
@A B11091202163000000000000001

Search for: ^(.{3})(.{2})(.{7})(.{4})(.{9})(.{5})
Replace with: \1.....\2 \3____\4----\5~~~~\6

The result looks like this:
@A .....B2 1091130____1700----000000000~~~~00001
@A .....B1 1091202____1630----000000000~~~~00001

Note that the first group does include the space char before the period delimiters. This sample is just to show that any char can be used as a separator, you would probably only use one, like the period. That result would look like this:
@A .....B2.....1091130.....1700.....000000000.....00001
@A .....B1.....1091202.....1630.....000000000.....00001

Again this will properly handle any number of space chars in any of the fields.
Hope this was helpful.............good luck,
Bob
Post Reply