Deleting End Blank Spaces

SavatageSavatage Member Posts: 7,142
edited 2011-09-28 in Navision Attain
I have a project I want to do because it's been bugging me forever.

When we switched to Nav a long while ago we imported our data like everyone else. All of our cust names, address, city etc. have lots of blank spaces at the end so when you put them together you get
NEW YORK__________, NY instead of
NEW YORK, NY for example.

I would like to create a report to wipe out these trailing Blanks but I am having trouble. I've read about "Hard Blanks" in previous posts so I went the Char route.

OnPreDataItem()
MyChar := 255;
MyText := FORMAT(MyChar);

OnAfterGetRecord()
FOR i := 1 TO STRLEN(Vendor.City) DO
BEGIN
IF (Vendor.City <> ' ') THEN
NewCity :=DELCHR(Vendor.City,'>',MyText);
END;

Vendor.MODIFY;

Can you help me point to where I'm going wrong?

Should I be Deleting Characters or Rebuilding the String?

Answers

  • nunomaianunomaia Member Posts: 1,153
    With this code you will delete all blank chars.

    So New York will become NewYork.

    Until there is double blank, delete that string.

    WHILE STRPOS(String, ‘  ‘) <> 0 DO BEGIN
     . . .
    
    END;
    
    
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • SavatageSavatage Member Posts: 7,142
    > Trailing character in String that matches a character in Which.

    am I not using this correctly?
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Umm... This may seem obvious, but you forgot the:

    Vendor.City := NewCity;

    before the MODIFY statement.
  • ara3nara3n Member Posts: 9,256
    wouldn't be easier to use the DELCHR function?
    Vendor.City := delchr(Vendor.City,'>',' ');
    Vendor.MODIFY; 
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • krikikriki Member, Moderator Posts: 9,112
    And including hard blanks:
    txtBlanks := '  '; // 2 blanks
    txtBlanks[1] := 255;
    Vendor.City := DELCHR(Vendor.City,'>',txtBlanks);
    Vendor.MODIFY;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • WaldoWaldo Member Posts: 3,412
    What do you mean with "hard" blanks? :-k
    "googling" didn't give me any result :cry:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • krikikriki Member, Moderator Posts: 9,112
    Waldo wrote:
    What do you mean with "hard" blanks? :-k
    "googling" didn't give me any result :cry:
    Hard blanks SEEM to be blanks if you show the string. But if you test on ' ', you won't find them because they have ASCII-code=255.
    It is a handy way to insert some 'blanks' to be seen but they don't behave like blanks.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • WaldoWaldo Member Posts: 3,412
    Ah ... never had any problems with this. I thought "hard" blanks were blanks who were excited :wink:

    Anyway ...

    I once had a job where I had to import purch. invoices from an AS/400. For one reason or another, all imported fields ended with blanks at the end (filling the field). I used ara3n's code for this, and everything worked just fine ... so I guess no hard blanks there... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • SavatageSavatage Member Posts: 7,142
    edited 2006-11-14
    I knew that array was killing me..thanks

    This is the greatest code in the history of Navision!!!!

    (for me)

    HA HA!! \:D/ \:D/ \:D/
  • SavatageSavatage Member Posts: 7,142
    deadlizard wrote:
    Umm... This may seem obvious, but you forgot the:

    Vendor.City := NewCity;

    before the MODIFY statement.

    I used Newcity - cause I didn't want to change the actual city until I knew it worked.
  • DenSterDenSter Member Posts: 8,307
    Waldo wrote:
    I thought "hard" blanks were blanks who were excited :wink:
    Stuff you run into while searching Mibuso :mrgreen:
Sign In or Register to comment.