/*REXX*/ /* XWord routines. These routines allow you to perform REXX WORD handling on strings that use a character other than a space to limit the words. Extremely hand when dealing with something link comma delimited data. Mark McDonald */ /*---------------------------------------------------------------*/ /* Returns the length of the Nth word in a string delimited by */ /* character XDL */ /* X = String N = Word number XDL = character delimiter */ /* Example: */ /* X = "This , is a test, of this , routine" */ /* TR = XWORDLENGTH(X,2,",") */ /* TR = 11 */ /*---------------------------------------------------------------*/ XWORDLENGTH: PROCEDURE PARSE ARG X, N, XDL IF N > XWORDS(X,XDL) THEN RETURN (0) X = XLATE(X,XDL) WL = WORDLENGTH(X,N) RETURN (WL) /*---------------------------------------------------------------*/ /* Returns the character position of the Nth word in a string */ /* delimited by character XDL */ /* X = String N = Word number XDL = character delimiter */ /* Example: */ /* X = "This , is a test, of this , routine" */ /* TR = XWORDINDEX(X,2,",") */ /* TR = 7 */ /*---------------------------------------------------------------*/ XWORDINDEX: PROCEDURE PARSE ARG X, N, XDL RP = 0 IF N > XWORDS(X,XDL) THEN RETURN (0) X = XLATE(X,XDL) RP = WORDINDEX(X,N) RETURN (RP) /*---------------------------------------------------------------*/ /* Returns number of words in X delimited by character xdl */ /* Example: */ /* X = "This , is a test, of this , routine" */ /* TR = XWORDS(X,",") */ /* TR = 3 */ /*---------------------------------------------------------------*/ XWORDS: PROCEDURE PARSE ARG X, XDL X = XLATE(X,XDL) NWRDS = WORDS(X) RETURN (NWRDS) /*---------------------------------------------------------------*/ /* Returns N Word Delimited by character XDL in X */ /* Example: */ /* X = "This , is a test, of this , routine" */ /* TR = XWORDS(X,2,",") */ /* TR = " is a test, of this " */ /*---------------------------------------------------------------*/ XWORD: PROCEDURE PARSE ARG X, N ,XDL IF N > XWORDS(X,XDL) THEN RETURN ("") X = XLATE(X,XDL) X = WORD(X,N) X = XUNLATE(X) RETURN (X) /*---------------------------------------------------------------*/ /* Translates spaces to decimal character 253 */ /* Called by XWord routines */ /*---------------------------------------------------------------*/ XLATE: PROCEDURE PARSE ARG X, XDL X = TRANSLATE(X,D2C(253)," ") X = TRANSLATE(X," ",XDL) RETURN (X) /*---------------------------------------------------------------*/ /* Translates decimal character 253 to spaces */ /*---------------------------------------------------------------*/ XUNLATE: PROCEDURE PARSE ARG X X = TRANSLATE(X," ",D2C(253)) RETURN (X) /*---------------------------------------------------------------*/