ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

string to 2D array

Solved!
Go to solution

Hello

I have large string like this:

TITLE

n1
string1-1
string1-2
string1-3
n2
string2-1
string2-2
string2-3
n3
string3-1
string3-2
string3-3
...

n99

string99-1

string99-2

string99-3

 

 

And I want to create array:

n1 string1-1 string1-2 string1-3
n2 string2-1 string2-2 string2-3

...

 

I have tried using Spreadsheet to Array but haw to define delimiter

Any Suggestions?

0 Kudos
Message 1 of 5
(7,005 Views)

Assuming that all the lines end in the same delimiter, there will be a two-step process. First convert it into a 1D array using the line delimiter and then reshape the 1D array into a 2D array.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(6,997 Views)

You can convert the String to a 1D Array and then reshape that to get a 2D Array. If you are sure about the number of elements thats is going to proceed after n then try this method.

 

String to 2D.png

 

String to 2D_FP.png

-----

The best solution is the one you find it by yourself
Message 3 of 5
(6,996 Views)

thanks,

but can I define that all n1, n2 ... n99 will be considered as delimitters?

Making some regular expression like n[0-9]+\n  ?

0 Kudos
Message 4 of 5
(6,990 Views)
Solution
Accepted by pawhan11

Not with the spreadsheet string to array function. For that you would need to parse the string in a loop first on the "n" values and then parse each segment thus found into a 1D array using the line delimiter. Combining all these 1D arrays will give you a 2D array.

 

Use the match pattern function for the initial segmentation.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 5
(6,986 Views)