Focal Point
[SOLVED] How to add 's or ' to the end of a variable

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5167051766

February 07, 2014, 01:50 PM
Joel Elscott
[SOLVED] How to add 's or ' to the end of a variable
Hi,
This is my first post on this forum, so please be kind. Smiler

I need to add either a 's or ' to the end of my variable, depending on if the variable ends in an "s" or not.

For example:
John's Snapshot
or
Lucas' Snapshot

I can do this with JavaScript with the code below, but I'm not sure how to do this with the WebFOCUS Language. Thanks in advance.

function setFirstName() {
var s = (local_ibi_client_fname.charAt(local_ibi_client_fname.length-1) == 's')? "'" : "'s";
document.getElementById('client_fname').innerHTML = local_ibi_client_fname + s + " Snapshot";
}

This message has been edited. Last edited by: <Kathryn Henning>,


WebFOCUS 8.2.03
z/OS
February 07, 2014, 03:28 PM
jfr99
Hi,

How about this:

-*
-SET &FNAME = 'John';
-*-SET &FNAME = 'Lucas';
-*
-SET &FN_LST = SUBSTR(&FNAME.LENGTH, &FNAME, &FNAME.LENGTH, &FNAME.LENGTH, 1, 'A1');
-SET &FN_NEW = IF &FN_LST EQ 's' THEN &FNAME || ''' Snapshot' ELSE &FNAME || '''s Snapshot';
-*
-TYPE FNAME ------ &FNAME
-TYPE FN_LST ----- &FN_LST
-TYPE FN_NEW ----- &FN_NEW
-EXIT
-*

Give it a try and let me know.


WebFocus 8.201M, Windows, App Studio
February 07, 2014, 03:50 PM
Joel Elscott
Perfect! Thank you!


WebFOCUS 8.2.03
z/OS
February 08, 2014, 06:41 PM
njsden
If you're planning on using that variable in any FOCUS expression, such as a DEFINE or WHERE clause, make sure to suffix it with .QUOTEDSTRING instead of enclosing it in single quotes as that apostrophe in the data may cause some issues.

-* In a DEFINE expression
DEFINE FILE BLAH
FULL_NAME/A60 = &FN_NEW.QUOTEDSTRING;
END
...
TABLE FILE BLAH
PRINT ....
WHERE NAME EQ &FN_NEW.QUOTEDSTRING
END




Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
February 09, 2014, 03:38 PM
Waz
I would also syggest that you truncate or right justify the variable before getting the last char, just in case there are trailing spaces.

-SET &FNAME = TRUNCATE(&FNAME) ;
or
-SET &FNAME = RJUST(&FNAME.LENGTH,&FNAME,'A&FNAME.LENGTH') ;



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!