I couldn’t live without “Multi-line String to Array”

Posted on Wednesday 11 April 2007

This is the sixth article of “The OpenG VIs that I couldn’t live without“, a series of articles showing some of my favorite OpenG VIs. In this article, I’m going to show a very useful VI, Multi-line String to Array, that is used to convert a multi-line string into a 1D array of strings, so that you can process individual lines (in a For Loop, for example).

One of the great things about this VI is that it automatically handles any variety of different end of line (EOL) characters (see wikipedia definition of Newline) that can be found in various platforms (for example: Mac, Linux, and Windows).

Let’s take a look at a quick example of this VI in action. In this example (shown below), we are converting a string with five lines into an array with five elements — one element for each line of the input string.

That’s all there is to it!

Now, you might be thinking to yourself, “How do I get rid of the blank (third) line?” That’s easy! Just use Filter 1D Array (which we learned about in our last article), as shown in the screenshot, below (wiring an Empty String constant to the “items to filter” input):

If you want to give this VI a try, you can obtain it using VI Package Manager (VIPM). Simply select the OpenG String Library (the oglib_string package from within VIPM), you will find the OpenG String Tools palette in the Functions palette under the OpenG submenu. (See here for a quick guide on how to install OpenG on VIPM.)

No comments have been added to this post yet.

Leave a comment



Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.

RSS feed for comments on this post |


Bad Behavior has blocked 5047 access attempts in the last 7 days.