Search code examples
foxpro

Remove trailing zero's and decimal point in Visual FoxPro 9


I know this programming language is pretty obsolete, but my company still uses it and it's hard to find specific help with these kinds of things online because of it being unsupported. I searched for a few options on here but found nothing.

Here's what my data looks like: 8005551234.000000

Here's what I need my data to look like: 8005551234

The reason it's showing up with the trailing zero's is because I'm assuming when I imported the data into FoxPro via an excel add on the field was an integer field, and when it was converted to a dbf it needed to be a character field.

I've played around with the TRANSFORM function a bit, but I can't seem to figure it out.

My field name is "Phone" if that helps...

Thanks in advance for your support!


Solution

  • If the field "phone" doesn't have hyphens in it as commented by Frank in another answer, you can always strip by using LEFT( x, at()).. such as

    replace Phone with left( phone, at( ".", phone ) -1 );
        for at( ".", phone ) > 0
    

    If you have a format with decimals as place-holders for the phone, such as

    1.800.TRY.MORE.

    You might have to use the optional 3rd parameter of "AT()" function which indicates which "." instance you are interested in. In the example of 1.800... you could try

    replace Phone with left( phone, at( ".", phone, 4) -1 );
        for at( ".", phone, 4 ) > 0
    

    AT() function is basically

    Look for "X" found in string "Y" and optionally, look for the "n" instance such as AT( X, Y, n )

    Hope this helps.