9.2 Concatenate string and values of other types

 

Concatenate a string and one or more values of other data types.
We have two text files and want to search for each string of text file 1 in text file 2 and return result as follows:

file1
like parks
went out
go out
file2
I like to go out because I like parks.
Ben does not go out much.
Shelly went out often but does not like parks.
Harry does not go out neither does he like parks.

Expected output result:

Member
Q1. like parks
I
Shelly
Harry
Q2. went out
Shelly
Q3. go out
I
Ben
Harry

SPL uses operator / to concatenate string and values of other data types.

SPL script:

A
1 =file(“file1.txt”).read@n()
2 =file(“file2.txt”).read@n()
3 =A1.conj((“Q”/#/"."/~)|A2.select(pos(~, A1.~)).(~.words()(1)))

A1 Read text file 1.
A2 Read text file 2.
A3 Loop through each string of text file 1, find them in text file 2 and get the first English word in the corresponding string. Precede each group of search result with Q, ordinal number of A1’s string member and the current member. The ordinal number is the integer type, and it is concatenated using operator /.

Execution result:

Member
Q1. like parks
I
Shelly
Harry
Q2. went out
Shelly
Q3. go out
I
Ben
Harry