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.
Separate Command on New Line
Moderators: Dorian (MJT support), JRL
Re: Separate Command on New Line
Hi, one way is to use RegEx> to get each line separately:
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, ...).
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.
*/
(?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, ...).
Re: Separate Command on New Line
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.
*/