This function takes a string (in this case, a comma delimited string)
and strips out the commas. I has as an input parameter what the
delimiter is and if you want the delimiter to be replaced with blanks.
Is this a good approach for a function? What are the different ways to
do this?
What (if any) is the performance hit on using functions. This one would
most likey be would be external and run from a persistent procedure.
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
/**********************************************************************************\
Function: ParseString
Desc: This function receives, as input, a char string (string
being parsed),
the string delimiter and whether or not you want spaces to
replace
the delimiter. It then returns a new string minus the
delimiters.
For instance, DISPLAY ParseString(cWord,",",1) will result
in
"This is my string."
cWord was "This,is,my,string."
Mods: 11/28/99 JAM Created
\**********************************************************************************/
FUNCTION ParseString RETURNS CHARACTER
(INPUT cString AS CHAR,
INPUT cRemoveChar AS CHAR,
INPUT iAddSpace AS INT).
DEF VAR cParsedString AS CHAR NO-UNDO.
DEF VAR i AS INT NO-UNDO.
CASE iAddSpace:
WHEN 1 THEN /* Add space between words */
DO i = 1 TO NUM-ENTRIES(cString):
ASSIGN
cParsedString = IF cParsedString = "" THEN
ENTRY(i,cString,cRemoveChar)
ELSE cParsedString + " " +
ENTRY(i,cString,cRemoveChar).
END.
OTHERWISE /* No space added */
DO i = 1 TO NUM-ENTRIES(cString):
ASSIGN
cParsedString = IF cParsedString = "" THEN
ENTRY(i,cString)
ELSE cParsedString +
ENTRY(i,cString).
END.
END CASE.
RETURN cParsedString.
END FUNCTION. /* ParseString */
DISP ParseString(DBPARAM(1),",",1) FORM "X(55)".
[/code]
and strips out the commas. I has as an input parameter what the
delimiter is and if you want the delimiter to be replaced with blanks.
Is this a good approach for a function? What are the different ways to
do this?
What (if any) is the performance hit on using functions. This one would
most likey be would be external and run from a persistent procedure.
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
/**********************************************************************************\
Function: ParseString
Desc: This function receives, as input, a char string (string
being parsed),
the string delimiter and whether or not you want spaces to
replace
the delimiter. It then returns a new string minus the
delimiters.
For instance, DISPLAY ParseString(cWord,",",1) will result
in
"This is my string."
cWord was "This,is,my,string."
Mods: 11/28/99 JAM Created
\**********************************************************************************/
FUNCTION ParseString RETURNS CHARACTER
(INPUT cString AS CHAR,
INPUT cRemoveChar AS CHAR,
INPUT iAddSpace AS INT).
DEF VAR cParsedString AS CHAR NO-UNDO.
DEF VAR i AS INT NO-UNDO.
CASE iAddSpace:
WHEN 1 THEN /* Add space between words */
DO i = 1 TO NUM-ENTRIES(cString):
ASSIGN
cParsedString = IF cParsedString = "" THEN
ENTRY(i,cString,cRemoveChar)
ELSE cParsedString + " " +
ENTRY(i,cString,cRemoveChar).
END.
OTHERWISE /* No space added */
DO i = 1 TO NUM-ENTRIES(cString):
ASSIGN
cParsedString = IF cParsedString = "" THEN
ENTRY(i,cString)
ELSE cParsedString +
ENTRY(i,cString).
END.
END CASE.
RETURN cParsedString.
END FUNCTION. /* ParseString */
DISP ParseString(DBPARAM(1),",",1) FORM "X(55)".
[/code]