Alpha Video Training
Results 1 to 19 of 19

Thread: Zero Length Strings?

  1. #1
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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. #2
    "Certified" Alphaholic
    Real Name
    JohnZaleski
    Join Date
    Oct 2000
    Posts
    1,736

    Default RE: Zero Length Strings?

    Try len(alltrim(prefix))

  3. #3
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default RE: Zero Length Strings?

    Tried that, still get the space.

  4. #4
    "Certified" Alphaholic
    Real Name
    JohnZaleski
    Join Date
    Oct 2000
    Posts
    1,736

    Default RE: Zero Length Strings?

    Not really an answer but this might work

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

  5. #5
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default 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. #6
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default RE: Zero Length Strings?

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

  7. #7
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default RE: Zero Length Strings?

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

  8. #8
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default 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. #9
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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. #10
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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. #11
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default 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. #12
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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. #13
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default 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. #14
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default 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. #15
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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. #16
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default 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. #17
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default RE: Zero Length Strings?

    Thanks for the explanation.

    Bill

  18. #18
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default 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. #19
    Member
    Real Name
    Bill Walker
    Join Date
    Jan 2004
    Posts
    146

    Default 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

Similar Threads

  1. Cannot Enter Certain Strings
    By Steve Andrews in forum Forum Usage
    Replies: 2
    Last Post: 09-27-2005, 11:44 AM
  2. Extracting strings from a Variable
    By John Castle in forum Alpha Five Version 5
    Replies: 10
    Last Post: 09-16-2005, 09:21 AM
  3. Strings in A5 null terminated?
    By Marcel Kollenaar in forum Alpha Five Version 6
    Replies: 6
    Last Post: 07-26-2004, 12:48 PM
  4. problem/w character strings:
    By BigMac in forum Alpha Five Version 5
    Replies: 11
    Last Post: 04-22-2004, 08:37 AM
  5. formatting strings & word_tagged_pattern
    By Blake in forum Alpha Five Version 5
    Replies: 1
    Last Post: 08-30-2003, 03:54 PM

Bookmarks

Posting Permissions

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