1. ## Zero Length Strings?

Could someone tell me why this expression has a space at the beginning? Prefix is empty. I have tried the alltrim function on the prefix field as well.

if(len(prefix)=0,"",alltrim(prefix)+" ")+alltrim(first_name)

Are not double quotes a zero length string?

Newbe Bill

2. ## RE: Zero Length Strings?

Try len(alltrim(prefix))

3. ## RE: Zero Length Strings?

Tried that, still get the space.

4. ## RE: Zero Length Strings?

Not really an answer but this might work

ALLTRIM(if(len(prefix)=0,"",alltrim(prefix)+" ")+alltrim(first_name))

5. ## RE: Zero Length Strings?

Must be some other issue

prefix = ""
first_name = "Tom"
? if(len(prefix)=0,"",alltrim(prefix)+" ")+alltrim(first_name)
= "Tom"

prefix = " "
first_name = "Tom"
? if(len(prefix)=0,"",alltrim(prefix)+" ")+alltrim(first_name)
= " Tom"

6. ## RE: Zero Length Strings?

That is the way I got what I wanted but as you said, it doesn't answer the question.

7. ## RE: Zero Length Strings?

That's what I'm looking for, why does my expression not work?

8. ## RE: Zero Length Strings?

Bill,

As Stan mentioned, something else must be going on. Show us the whole script, including especially the pieces that assign an initial value to ' prefix '.

-- tom

9. ## RE: Zero Length Strings?

Here goes,

Prefix is Mr. Mrs. .... Most of the time it is empty or not used.

In a calculated field on a form I have the expression:
*******************
if(len(prefix)=0,"",alltrim(prefix)+" "))+alltrim(first_name)+" "+(if(len(middle_name)=0,'',alltrim(middle_name)+" "))+alltrim(last_name)+(if(len(suffix)=0,"",' '+alltrim(suffix)))
*********************
With out the first alltrim function I get a space at the beginning of the field only if prefix is empty, if prefix is not empty like 'Mr.' then there is no space at the beginning of the field.

I have checked the prefix field in it appears to be empty, when I move to the field the curser is in the left most position.

Thanks for everyones help with this.
Bill

10. ## RE: Zero Length Strings?

Oops, Try this,

Here goes,

Prefix is Mr. Mrs. .... Most of the time it is empty or not used.

In a calculated field on a form I have the expression:
*******************
if(len(prefix)=0,"",alltrim(prefix)+" "))+alltrim(first_name)+" "+(if(len(middle_name)=0,'',alltrim(middle_name)+" "))+alltrim(last_name)+(if(len(suffix)=0,"",' '+alltrim(suffix)))
*********************
I get a space at the beginning of the field only if prefix is empty, if prefix is not empty like 'Mr.' then there is no space at the beginning of the field.

I have checked the prefix field in it appears to be empty, when I move to the field the curser is in the left most position.

Thanks for everyones help with this.
Bill

11. ## RE: Zero Length Strings?

Bill,

If prefix is a field in a table (which I'm sure it is by the context you've supplied), LEN(prefix) will always equal the width of the field in the table. It does not matter what you've entered into the field, the character field stored is always the width of the field.

Hence, with your equation, you get a trimed prefix followed by a space, per your expression.

Regards,

Ira

12. ## RE: Zero Length Strings?

That's it! Thanks Ira

Thanks to everyone who replied. I hope to get up to speed with Alpha and xbasic before too long and be able to give help in return.

Bill

13. ## RE: Zero Length Strings?

Bill, it's helpful to remember that the DBF format uses fixed width fields. Each record is the same size (in bytes) even if some of it's fields are empty. This trick is achieved by storing blank spaces in each empty field, and by padding 'short' field values with extra spaces.

-- tom

14. ## RE: Zero Length Strings?

So, in your case, the Prefix field wasn't truly empty, it was full of blank space characters. While it appeared empty it wasn't, if you see what I mean. -- tom

15. ## RE: Zero Length Strings?

Thanks Tom, I kind of figured that out with Ira's reply.

This is the first time I have seen this type of arrangement. Usually I see nulls or empty (zero length)strings (access and sql). Do you know what the reasoning is for padding every charater field?

Bill

16. ## RE: Zero Length Strings?

Bill,

There is no padding per say, but the value you enter is placed in the fixed field. There is no character length of the actual string stored, so the rest of the characters are blanked. It's the nature of the DBF format.

Regards,

Ira

17. ## RE: Zero Length Strings?

Thanks for the explanation.

Bill

18. ## RE: Zero Length Strings?

Bill,

Why? well I guess you'd have to go back to the original designer of the DBF format. The blank space characters were probably used because he wanted record sizes fixed, and because he stored all field values as text, even numeric values. -- tom

19. ## RE: Zero Length Strings?

Thanks Tom,

I guess there could be some advantages in having fixed length records. File size not being one of them, but stability is much more important so if it works.....

Do you know a way I could get .0001 cents for each time a trim function is used ;)

Thanks again to everyone who responded.
Bill

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•