Working with Numbers

General questions about using TextPad

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

Post Reply
BBowers
Posts: 17
Joined: Fri Jan 05, 2007 4:19 pm
Location: Colorado

Working with Numbers

Post by BBowers »

-94.1476, 36.3341,
-94.981617, 35.881339,
-94.22168, 36.36895,
-97.480064, 25.921765,
-104.6628, 38.23505,

This is a short section of hundreds of records in a large text file.

I want to add two zero's to the end of both sets of all numbers when the numbers only have four decimal places. -94.1476, will become -94.147600, and -104.6638 becomes -104.662800. i.e. I don't want to effect the numbers that already have six decimal places.

I really am having a hard time understanding how to work with numbers. Mostly with the Replace part of the Find/Replace.

If anyone can help, it will be really appreciated.

Thanks, Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

then search for a dot, 4 digits and a comma (put () aroud the 4 digits so they can be used in replacement:

Search for
\.([0-9]{4}),

Replace by
.\100,
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

More generally:
Find what: \<([0-9]{4})\>
Replace with: \100

[X] Regular expression
\< and \> are anchors; they match zero characters, but fix a position at the beginning or end (respectively) of a word (a digit sequence counts as a word).

Alternatively,
Find what: \<[0-9]{4}\>
Replace with: \000

[X] Regular expression
That's \0 followed by 00. \0 represents whatever the whole regex matched.

These and MudGuard's solution assume you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

ben's solution does also replace if the part of the number before the . has 4 digits, i.e. 1234.123456 will become 123400.123456 ...
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You're right! My exclusion of the dot in the regex was incorrect in this case.
BBowers
Posts: 17
Joined: Fri Jan 05, 2007 4:19 pm
Location: Colorado

Post by BBowers »

Thanks a lot that really helped. I'm getting there slowly but surely.

Takes a little getting used to, to figure out these Regular Expressions.
Post Reply