Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [solved] How to add trailing spaces to a string to make it fixed length?
Go
New
Search
Notify
Tools
Reply
  
[solved] How to add trailing spaces to a string to make it fixed length?
 Login/Join
 
Platinum Member
posted
I have some input strings of which the length are different. Is there a function I can patch it with trailing spaces to make it fixed length?

example:

'F121' -> 'F121 ' (A5)
'bdd' -> 'bdd ' (A5)

Thanks!

This message has been edited. Last edited by: bug,


7.66 and 7.704
System: Windows / AIX / Linux
Output: Mostly HTML, with some PDF, Excel and Lotus(!)
 
Posts: 147 | Location: Toronto (GTA) | Registered: May 25, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
I do this....
quick & dirty

-DEFAULT &mystring = '123';
-TYPE &mystring  &mystring.LENGTH
-SET &mystring = &mystring | '     ';
-SET &mystring = EDIT( &mystring.QUOTEDSTRING, '99999');
-TYPE &mystring  &mystring.LENGTH




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Reply With QuoteReport This Post
Platinum Member
posted Hide Post
This works Smiler

Thanks!


quote:
Originally posted by susannah:
I do this....
quick & dirty

-DEFAULT &mystring = '123';
-TYPE &mystring  &mystring.LENGTH
-SET &mystring = &mystring | '     ';
-SET &mystring = EDIT( &mystring.QUOTEDSTRING, '99999');
-TYPE &mystring  &mystring.LENGTH


7.66 and 7.704
System: Windows / AIX / Linux
Output: Mostly HTML, with some PDF, Excel and Lotus(!)
 
Posts: 147 | Location: Toronto (GTA) | Registered: May 25, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Could not resist using one of my favourite techniques, which is useful if there are many variables with different length requirements:
DEFINE FUNCTION VARFILL (STRING/A200,LENGTH/I3)
VARFILL/A200V=SUBSTV(200,STRING,1,LENGTH,VARFILL);
END
-RUN

-DEFAULT &mystring = '123';
-TYPE &mystring  &mystring.LENGTH
-SET &mystring = VARFILL(&mystring.QUOTEDSTRING,5);
-TYPE &mystring  &mystring.LENGTH


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Be aware of the special case where the value of &mystring is FOC_NONE or _FOC_NULL. You would end up with 'FOC_N' or '_FOC_' respectively, neither of which do what's expected of them.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1644 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Good point.
DEFINE FUNCTION VARFILL (STRING/A200,LENGTH/I3)
LENGTH/I3 = IF STRING LIKE 'FOC_%' OR STRING LIKE '_FOC_%' THEN ARGLEN(200,STRING,'I3') ELSE LENGTH;
VARFILL/A200V = SUBSTV(200,STRING,1,LENGTH,'A200V');
END
-RUN

-DEFAULT &mystring = 'FOC_NONE';
-TYPE &mystring  &mystring.LENGTH
-SET &mystring = VARFILL('&mystring.EVAL',5);
-TYPE &mystring  &mystring.LENGTH

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
And don't forget FPRINT (though you're 766 version may not have access to it, you're 7704 will)

-DEFAULTS &STR1='F121';
-TYPE &STR1 &STR1.LENGTH
-SET &STR1TYPE=IF &STR1.TYPE EQ N THEN I ELSE A;
-SET &STR2=FPRINT('&STR1.EVAL',&STR1TYPE.EVAL&STR1.LENGTH,'A5');
-TYPE &STR2 &STR2.LENGTH



In FOCUS since 1985 - WF 8.009/8.104 Win 8 Outputs: ALL of 'em! Adapters: Sql Server Teradata Oracle
 
Posts: 161 | Location: Dallas, TX | Registered: February 20, 2009Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [solved] How to add trailing spaces to a string to make it fixed length?

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.