Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Parsing multiline strings

Parsing multiline strings

Parsing multiline strings

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.


RE: Parsing multiline strings

/* 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
say 'word 1 of each line'
Do w = 1 to i
say WordOne.w
Exit 0

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close