Deleting End Blank Spaces

Savatage
Member Posts: 7,142
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?
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?
0
Answers
-
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;
0 -
> Trailing character in String that matches a character in Which.
am I not using this correctly?0 -
Umm... This may seem obvious, but you forgot the:
Vendor.City := NewCity;
before the MODIFY statement.Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
wouldn't be easier to use the DELCHR function?
Vendor.City := delchr(Vendor.City,'>',' '); Vendor.MODIFY;
0 -
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!0 -
Waldo wrote:What do you mean with "hard" blanks? :-k
"googling" didn't give me any result
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!0 -
Ah ... never had any problems with this. I thought "hard" blanks were blanks who were excited
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... .0 -
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/0 -
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.0 -
Waldo wrote:I thought "hard" blanks were blanks who were excited0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions