Remove period problem

Ok,
this is driving me nuts.

I need to remove a period which is followed by 3 or more digits only.
If a period is followed by only 2 digits, then keep it.

So, if the text field contains this - keep the period and do nothing:
34.50

BUT, if the textfield contains something like this:
1.345.50
Remove the first period, so that it ends up like this:
1345.50

I cannot work out how to achieve this. I have looked in the LR at Split, Left, Right, NthField - but cannot seem to get this working.

Any help would be much appreciated.

``````x=instr(s,".")
if x<len(s)-3 then s=left(s,x-1)+mid(s,x+1)``````

Thank you so much Dave - I think that was the only thing in the LR I never looked at.
So I just need to replace s with the TextField in question, and I should be good to go.

Thank you.

[quote=146316:@Dave S]

``` dim s as string=textfield1.text x=instr(s,".") if x<len(s)-3 then s=left(s,x-1)+mid(s,x+1) textfield1.text=s ```[/quote]

don’t use the control in all the places “s” is defined… too much overhead

So what would you do with 1.345.678.90

You can do this with a regular expression too.

``````dim rx as new RegEx
rx.SearchPattern = "\\.(?=.*\\.)"
rx.Options.ReplaceAllMatches = true
s = rx.Replace( s )``````

The pattern identifies every period in the string except for the last one and removes it.

``````dim s as string=textfield1.text
x=instr(s,".")
while x<len(s)-3
s=left(s,x-1)+mid(s,x+1)
x=instr(s,".")
wend
textfield1.text=s``````

Kem… I don’t see where you RegEx enforces the “followed by 3” rule

I changed the conditions of the test.

It looked to me like what Richard really needed was to remove all the periods but the last one. However, this pattern will do both.

``rx.SearchPattern = "\\.(?=.*\\.|\\d{3,})"``

It looks for periods where there is another period later in the string, or where it is followed by three of more digits, and removes them.

[quote=146324:@Kem Tekinay]

``` rx.SearchPattern = "\\.(?=.*\\.|\\d{3,})" ```[/quote]
Magic. And it looks like chickenpoo.

Fortunately, we can all be magicians. And are.

To break it down:

``````\\.     # Look for a period
(?=    # Start a positive lookahead for...
.*\\.   # another period somewhere down the line...
|      # or...
\\d{3,} # three or more digits
)      # End the positive lookahead``````

Not sure how to implement this, with my textfield though:

``rx.SearchPattern = "\\.(?=.*\\.|\\d{3,})"``

Thank you so much everyone - very much appreciated.

``````dim s as string=textfield1.text
dim rx as new RegEx
rx.SearchPattern = "\\.(?=.*\\.|\\d{3,})"
rx.Options.ReplaceAllMatches = true
s = rx.Replace( s )
textfield1.text=s``````

Thank you so much Dave and Kem - I can now START to learn how to use regex.
I very much appreciate both your help to get this combined solution.

Thank you.

Now I have to go back & review all your code since we now know you pull the Kobayashi Maru solution

[quote=146327:@Oliver Osswald]Magic. And it looks like chickenpoo.
;-)[/quote]
Perl ! as in “someone spewed punctuation all over my screen” Perl

Ok, I need some help with my final problem regarding removing periods.

I need to remove all periods (except the last) from the values in column 4 of each row - then - add them all together.

So if column 4 looks like this:
1.234.50
3.456.00
2.332.67

I need to convert the values (but not display them) to:
1234.50
3456.00
2332.67

Could more knowledgeable members please advise me of the best route to achieve this.

I was thinking of looping through the column values and putting them in an array; then remove the periods from each array element using Kems RegEx; then add up all the elements to reach a final figure.

Does this sound like I am on the correct route - or this there a much better way of achieving this?

[quote=146349:@Richard Summers]I was thinking of looping through the column values and putting them in an array; then remove the periods from each array element using Kems RegEx; then add up all the elements to reach a final figure.

Does this sound like I am on the correct route - or this there a much better way of achieving this?[/quote]

That’s the way.

Wow - I surprised myself there
Thanks Kem.

I understood that

I’m a geek :-o

OK, almost there (I think) - here is what I have so far:
I am having trouble with the very last part - adding up each element.

[code]// LOOP THROUGH COLUMN 4 AND INSERT RESULTS INTO AN ARRAY
Dim ColumnArray() As String
for i as integer = 0 to AccountsWindow.lb_accounts.ListCount -1
ColumnArray.append(AccountsWindow.lb_accounts.Cell(i, 4))
next

// LOOP THROUGH EACH ARRAY ELEMENT AND STRIP ALL PERIODS (EXCEPT THE LAST)
for i2 as integer = 0 to ColumnArray.Ubound -1
dim element as string = str(ColumnArray(i2))
dim rx as new RegEx
rx.SearchPattern = “\.(?=.*\.|\d{3,})”
rx.Options.ReplaceAllMatches = true
element = rx.Replace( element )
next

// ---------------------------------------- LOOP THROUGH AND ADD UP ALL THE ARRAY ELEMENTS
Dim Amount As Integer
for i3 as integer = 0 to ColumnArray.Ubound -1
Amount = Amount + val(ColumnArray(i3))
next
[/code]

How am I doing so far? - I am pretty sure I have done something wrong somewhere, but can’t test as I am on my iPad