Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
rajan_burad
Active Participant
Hello Experts,

I was trying to understand how does 'separator' in word_ext() works. How does it picks the string? After exploring and experimenting, I recorded my observation.

Here it is:

word_ext() is used to extract a string from a list of strings provided as input. The input provided by user will have a list of delimited strings.

word_ext( input string (varchar), word number to extract (int), separator (varchar) )

 

Consider the input string: - It has 10 delimited strings, the delimiter is comma (,) and semicolon(;)

$row = 'a,b,c;d,e,f,g;h,i;j';

$row = word_ext( $row ,3,',');

Since strings are separated by comma and semicolon but in word_ext function we’ve specified comma (,) as separator so BODS will assign numbers as soon as it encounters a comma.

Like $row = 'a,b,c;d,e,f,g;h,i;j';

When first comma (,) is encountered it assigns 1 previous string and 2 to next string and this process hence goes on. It’ll ignore all the other alphanumeric characters and will only consider comma (,) i.e. ‘a’ will be assigned number 1, ‘b’ will be assigned 2, ‘c;d’ will be assigned 3 because it’ll overlook other alphanumeric characters and will look only for strings separated by comma.

Hence internally it'll be like this,

$row = 'a(1),b(2),c;d(3),e(4),f(5),g;h(6),i;j(7)';

Since we need to extract the 3rd word from given input string so,

Output = c;d

If $row = word_ext( $row ,4,',');

Output = e

Now we give separator as semi-colon (;)

If $row = word_ext( $row ,4,';');

Processing:  $row = 'a,b,c(1);d,e,f,g(2);h,i(3);j(4)';

 

Output = ‘j’

 

Thanks!!
4 Comments
Labels in this area