Friday, August 5, 2016

REXX String Manipulation : Substr, Pos, Words

REXX String Manipulation:

i. Substr:

Variable1 = 'Hello World'
Result = Substr(Variable1, 1, 5)

This would return the first 5 characters from the variable1. 

Result would be 'Hello'.

Variable1 = 'Hello World'
Result = Substr(Variable1, 7, 5)

This would return 5 characters from the 7th character of the variable1. 

Result would be 'World'. 

ii. Pos:

Very useful command to search for a string in a Variable.

Variable1 = 'Hello World'

My Search String is 'World'.

Hence, We shall code like:

 if(Pos(Variable1,'World')>0) then Say 'World is found'.

Result would be the display of 'World is found' since Pos command returns value 7 which is greater than 0.

If the search string is not found, it would return the value -1. 

iii. Words:

Words command return the number of words in a string. 

Variable1 = 'Hello World'

Num_Words = Words(Variable1)

Num_Words would be containing the result 2 since Variable1 is containing two words. 

We shall make a loop over all the words and process each word. 

For example:

do i = 1 to Num_Words
then do
     Single_word = Word(Variable1,i)
     Call User_logic_function
end

1 comment:

  1. I really happy found these website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.
    Trend Micro Geek Squad
    Generally I do not read article on blogs, but I wish to say that this write-up very compelled me to try and do so! Your writing style has been amazed me. Thanks, quite nice post.

    ReplyDelete

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....