Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing multiline strings

Status
Not open for further replies.

crieman

Technical User
Feb 4, 2015
1
US
Hi All,
I have a multi-line string containing in a variable.
I have been trying to find a way to parse it - the first thing I want to know
is how many lines are in the string. I can't really use LINES since it only works against a file and I would rather not create a file just for this - would like to be be able to keep everything in the var. Once I know the number of lines, I would like to place the first word of each line in an array.
No I can get the first word of the entire string but have not been able to find anything out there quite along these lines.
I could probably use PARSE and break it apart at each LF but this seem pretty involved to something so simple.
I apologize for the basic question, but I just started dabbling in REXX recently - if I could use bash for this, I would already be done with it.
Any help is appreciated.

Thanks!
 
/* REXX */
/* # = the line delimiter (LF CRLF what ever) */
WordOne. = ''
String = "This is a multi#Line message. It has#3 lines of text."
StringX = String
Do i = 1 by 1 until StringX = ""
parse var StringX WordOne.i . '#' StringX
End
say 'word 1 of each line'
Do w = 1 to i
say WordOne.w
End
Exit 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top