I have a text file that I would like to read into a string array and then perform a string compare on all of the entries. How can I do this?


First, the *SREAD command can be used to read text from a file into an array. This is well documented.

*SREAD,my_array,some_file,txt

Since vector operations are not applicable to string arrays, the length of the array can be retrieved using *GET,,PARM.

*GET,num_lines,PARM,my_array,DIM,2

While there are no GET functions to directly compare two strings, an *IF statement can be used for the comparison. Also, the GET function, STRCOMP, can be used to remove blank lines from the string. Note how the string array is indexed in the following snippet.

*DO,ii,1,num_lines
! string arrays are indexed with row = 1 and col = line
*IF,STRCOMP(my_array(1,ii)),EQ,'STRS',THEN
! if the strings match, perform some operation
*ENDIF
*ENDDO





Show Form
No comments yet. Be the first to add a comment!