Separate Command on New Line

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Separate Command on New Line

Post by winstein » Wed Aug 10, 2016 10:43 am

When I want to separate a string by the amount of lines it has, what is the best way to do it? Currently, Separate is based on delimiters to determine the separation, but as far as I know, it's based on the character, which means that it's difficult to properly use a new line character.

Thanks for reading.
PPQ

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Separate Command on New Line

Post by hagchr » Wed Aug 10, 2016 11:21 am

Hi, one way is to use RegEx> to get each line separately:

Code: Select all

LabelToVar>TestString,strText
RegEx>(?m-s)^.+,strText,0,m,nm,0

/*
TestString:
Here is some text
spread over 3 lines
This is the last line.
*/
If you are new to RegEx> then what it means is
(?m-s) defines that ^ should match at the beginning of each line and that . (period) which normally matches all characters should not match the end-of-line character.

So in total, RegEx> is looking for lines (Start of line (^) followed by one or more characters (.+) except EOL).

In this example the variable nm will contain the number of matches, ie lines, and each line is contained in the array m (m_1, m_2, ...).

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Separate Command on New Line

Post by JRL » Wed Aug 10, 2016 2:07 pm

There is a built in variable for line separation. The variable is "crlf" which is short for carriage return / line feed. You can Separate> by "crlf" to divide a series of text lines.

Code: Select all

LabelToVar>TestString,strText
Separate>strText,crlf,m
/*
TestString:
Here is some text
spread over 3 lines
This is the last line.
*/

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts