PDA

View Full Version : Odd behavior with RTrim and LTrim



Gillian
July 18th, 2003, 02:04 PM
I'm having a very odd problem with the RTrim and LTrim functions. I've got a text file exported (using Redwing) from PDF, and I need to trim the trailing and leading spaces from a field I have. The field looks a bit like this:


100.00 43 VISION
80.00 I CHKG
540001.59 52 MEDI'm trying to use the LTrim and RTrim functions to return something just like this:


100.00 43 VISION
80.00 I CHKG
540001.59 52 MEDI can't show it well here, but the text IS spaced such that trimming the left spaces will return such uniform formatting. However, when I try to use LTrim (syntax: LTrim(Temp1) where Temp1 is the name of the field), it gives me text that looks like this:


100.00 43
80.00
540001.49 52It doesn't show the third section of the line, and doesn't always show the middle section of the line, with no apparent pattern.

When I use RTrim:


100
80
540001The pattern seems to be that it's trimming everything from the right up to the decimal point in the number!

Am I missing something simple here? I have considered that what look like spaces may actually be characters of some kind, but I'm not sure how I could find out what they are, or even how to get rid of them.

I hope this has made sense. I'll try to clarify anything that isn't clear.

Steve Caiels
July 18th, 2003, 03:43 PM
Hi Gillian,

The LTRIM(TEMP1) would do something similar to this if the field length of the calculated field was too low. Although I'd have expected to see the I on the 2nd example. The only explanation I can think of for the RTrim() example is that at some stage in the calculation, the field has been converted to a numeric with no decimal places. Are you also using the VAL() function, or are you just using LTrim() and RTrim()? I guess a sample file may be needed here. You may just have time to get one to US tech support.!! Or email one to me if you like, but it's 7pm on a Friday evening here, and I'm off to the pub!!

Cheers
Steve

[ July 18, 2003, 02:44 PM: Message edited by: Steve Caiels ]

Grant Perkins
July 18th, 2003, 03:49 PM
Gillian,

This is really dumb thought from me but, it is Friday and that a day when I often forget to check simple things so, here goes.

If I perform an Ltrim or Rtrim on a cut and paste version of your sample I get a new field of only 10 chars width default (using 5.02) which exhibits similar output to yours (but not identical). Have you tried changing the data and display widths for your resulting field(s)? I assume you are Ltrimming and the Rtrimming the result of that?)

Silly thought but one to eliminate from the possibilities I suspect. Just in case Friday has got to you! ;)

Grant


Originally posted by Gillian:
I'm having a very odd problem with the RTrim and LTrim functions. I've got a text file exported (using Redwing) from PDF, and I need to trim the trailing and leading spaces from a field I have. The field looks a bit like this:


100.00 43 VISION
80.00 I CHKG
540001.59 52 MEDI'm trying to use the LTrim and RTrim functions to return something just like this:


100.00 43 VISION
80.00 I CHKG
540001.59 52 MEDI can't show it well here, but the text IS spaced such that trimming the left spaces will return such uniform formatting. However, when I try to use LTrim (syntax: LTrim(Temp1) where Temp1 is the name of the field), it gives me text that looks like this:


100.00 43
80.00
540001.49 52It doesn't show the third section of the line, and doesn't always show the middle section of the line, with no apparent pattern.

When I use RTrim:


100
80
540001The pattern seems to be that it's trimming everything from the right up to the decimal point in the number!

Am I missing something simple here? I have considered that what look like spaces may actually be characters of some kind, but I'm not sure how I could find out what they are, or even how to get rid of them.

I hope this has made sense. I'll try to clarify anything that isn't clear.

[ July 18, 2003, 02:50 PM: Message edited by: Grant Perkins ]

Gillian
July 18th, 2003, 03:54 PM
redface.gif

Yep, the calculated field length seems to have been too low.

I'm not at all sure why RTrim was doing what it did, but now that I've changed the field length to an acceptable size, the problem has gone away.

Thanks!

Gillian
July 18th, 2003, 03:56 PM
Originally posted by Grant Perkins:
Just in case Friday has got to you! ;)

GrantIt most certainly has. I'm all ready for the weekend, right about now-ish.