ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Parse a long string into lines? (https://www.excelbanter.com/excel-programming/320463-parse-long-string-into-lines.html)

quartz[_2_]

Parse a long string into lines?
 
I have a long string that I need to parse into separate lines. Has anyone got
a function that will do this neatly? I'm having a devil of a time...

For example, parse the following:

This is an example of a string parser that will return only one
line at a time. The first line ends at "one" in the previous line and
it is marked by a "vbCr" character. The second line ends at
"and" and the third line ends at "at".

The above would return "This is an example of a string parser that will
return only one" as the first line;

The second line is "line at a time. The first line ends at "one" in the
previous line and", etc.

Each line is marked by a "vbCr" character...thanks in advance.

Bryan Dickerson

Parse a long string into lines?
 
If each line is marked with a "vbCR", then use the split function. It
produces a dynamic array.

Dim sArray() as string

sArray = split("text string goes here", vbCr)

' Then sArray(0) = "text up until vbCr"
' sArray(1) = "more text until another vbCr"

"quartz" wrote in message
...
I have a long string that I need to parse into separate lines. Has anyone

got
a function that will do this neatly? I'm having a devil of a time...

For example, parse the following:

This is an example of a string parser that will return only one
line at a time. The first line ends at "one" in the previous line and
it is marked by a "vbCr" character. The second line ends at
"and" and the third line ends at "at".

The above would return "This is an example of a string parser that will
return only one" as the first line;

The second line is "line at a time. The first line ends at "one" in the
previous line and", etc.

Each line is marked by a "vbCr" character...thanks in advance.





All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com