I tested this and it works ... note that starting position for substring is Length(string) - 1. This returns the last two characters.
vcSample = ABCDE.
Length(vcSample) = 5, substring(vcSample, 4, 2) returns "DE". Substring(vcSample, 3, 2) returnS "CD".
Def var vOpt as char no-undo initial "ABCDE".
Def var vctemp as char no-undo.
if length(vcOpt) >= 2 then do:
vcTemp = substring(vcOpt, length(vcOpt) - 1, 2).
return "String: " + vcOpt + " last-2: " + vcTemp.
end.
else return error "Syntax: test.substring,<string to test>".
If you need it often I would make it a function ...
FUNCTION fLastN RETURNS CHARACTER (vcOpt as CHAR, n as INT):
Def var vcTemp as char no-undo.
if length(vcOpt) >= n then do:
vcTemp = substring(vcOpt, length(vcOpt) - n + 1, n).
return vcTemp.
end.
else return error "String: " + vcOpt + " is too short".
/* NOTE THAT N = 0 might also return an error, past the end of the string! */
END FUNCTION.
Then yourVar = fLastN (JobAsmbl.Partnum, 2) NO-ERROR.
Cheers!
Christopher Heins
Sr. Progress Programmer/Analyst
Desk# 973-560-5370
Cell# 908-256-3662
Skype: cheins.nj
cheins@...
NOT INTENDED AS A SUBSTITUTE FOR A WRITING
NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO, SHALL CONSTITUTE A BINDING CONTRACT, OR ANY CONTRACTUAL OBLIGATION BY PNY, OR ANY INTENT TO ENTER INTO ANY BINDING OBLIGATIONS, NOTWITHSTANDING ANY ENACTMENT OF THE UNIFORM ELECTRONIC TRANSACTIONS ACT, THE FEDERAL E-SIGN ACT, OR ANY OTHER STATE OR FEDERAL LAW OF SIMILAR SUBSTANCE OR EFFECT. THIS EMAIL MESSAGE, ITS CONTENTS AND ATTACHMENTS ARE NOT INTENDED TO REPRESENT AN OFFER OR ACCEPTANCE OF AN OFFER TO ENTER INTO A CONTRACT. NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO SHALL ALTER THIS DISCLAIMER.
This e-mail message from PNY Technologies, Inc. is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
vcSample = ABCDE.
Length(vcSample) = 5, substring(vcSample, 4, 2) returns "DE". Substring(vcSample, 3, 2) returnS "CD".
Def var vOpt as char no-undo initial "ABCDE".
Def var vctemp as char no-undo.
if length(vcOpt) >= 2 then do:
vcTemp = substring(vcOpt, length(vcOpt) - 1, 2).
return "String: " + vcOpt + " last-2: " + vcTemp.
end.
else return error "Syntax: test.substring,<string to test>".
If you need it often I would make it a function ...
FUNCTION fLastN RETURNS CHARACTER (vcOpt as CHAR, n as INT):
Def var vcTemp as char no-undo.
if length(vcOpt) >= n then do:
vcTemp = substring(vcOpt, length(vcOpt) - n + 1, n).
return vcTemp.
end.
else return error "String: " + vcOpt + " is too short".
/* NOTE THAT N = 0 might also return an error, past the end of the string! */
END FUNCTION.
Then yourVar = fLastN (JobAsmbl.Partnum, 2) NO-ERROR.
Cheers!
Christopher Heins
Sr. Progress Programmer/Analyst
Desk# 973-560-5370
Cell# 908-256-3662
Skype: cheins.nj
cheins@...
NOT INTENDED AS A SUBSTITUTE FOR A WRITING
NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO, SHALL CONSTITUTE A BINDING CONTRACT, OR ANY CONTRACTUAL OBLIGATION BY PNY, OR ANY INTENT TO ENTER INTO ANY BINDING OBLIGATIONS, NOTWITHSTANDING ANY ENACTMENT OF THE UNIFORM ELECTRONIC TRANSACTIONS ACT, THE FEDERAL E-SIGN ACT, OR ANY OTHER STATE OR FEDERAL LAW OF SIMILAR SUBSTANCE OR EFFECT. THIS EMAIL MESSAGE, ITS CONTENTS AND ATTACHMENTS ARE NOT INTENDED TO REPRESENT AN OFFER OR ACCEPTANCE OF AN OFFER TO ENTER INTO A CONTRACT. NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO SHALL ALTER THIS DISCLAIMER.
This e-mail message from PNY Technologies, Inc. is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.