LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change 1D ARRAY to singles single string elements

Hi, 

     I have a row of data from sql

     It's have more data in row

     I need to split those data's

    Ex :

       Actual data

        "Rajesh","ramesh","raj"

       I expect element by element

        Element 1 Rajesh 

        Element 2 Ramesh

        Element 3 Raj

 

0 Kudos
Message 1 of 16
(1,229 Views)

@Rajeshe432 wrote:

Hi, 

     I have a row of data from sql

     It's have more data in row

     I need to split those data's

    Ex :

       Actual data

        "Rajesh","ramesh","raj"

       I expect element by element

        Element 1 Rajesh 

        Element 2 Ramesh

        Element 3 Raj

 


Your title is confusing. It is not clear what you have and what you want.

If ["Rajesh","ramesh","raj"] is a single string with comma delimiters, you can convert it into a 1D array using "spreadsheet string to array".

 

altenbach_0-1687438629992.png

 

 

Assuming   ["Rajesh","ramesh","raj"] is a 1D array of string with three elements, you can use index array to get any one. If you want to process them in order, autoindex using a FOR loop to iterate over the elements.

 

 

It would help if you could attach a simple VI that has your input and desired output.

0 Kudos
Message 2 of 16
(1,219 Views)

Hi Raj,

 


@Rajeshe432 wrote:

     I have a row of data from sql

     It's have more data in row

     I need to split those data's

    Ex :

       Actual data

        "Rajesh","ramesh","raj"

       I expect element by element

        Element 1 Rajesh 

        Element 2 Ramesh

        Element 3 Raj

 


To split a string into an array of substrings based on a delimiter char you may use SpreadsheetStringtoArray.

To remove quotation marks from strings you may use SearchAndReplaceString.

 

What have you tried and where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 16
(1,218 Views)

Hello,

I used "Spreadsheet String to Array" to separate my incoming data into individual lines. Now I have something like this:

["%f, %f, %f", "%f, %f, %f", "%f, %f, %f", ...]   Each string contains three comma-separated values.

 

What I would like to do is extract the three values from each string and place them into three separate float arrays.

For example, given:

["1,2,3", "4,5,6"]

 

I want to obtain:

Array 1: [1.0, 4.0]
Array 2: [2.0, 5.0]
Array 3: [3.0, 6.0]

 

How can I do this efficiently in LabVIEW?

Thanks in advance!

0 Kudos
Message 4 of 16
(354 Views)

Hi Quinon,

 


@Ouinon wrote:

How can I do this efficiently in LabVIEW?


  1. Use a FOR loop to iterate over each string.
  2. Inside the loop you use ScanFromString (as you already know from your other threads) to get three float values.
  3. Use autoindexing tunnels to create your required arrays…

Autoindexing is very efficient in LabVIEW!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 16
(338 Views)

You can convert a spreadsheet directly into a 2D-array if rows are separated by newlines

 

spreadsheet string to 2D arrayspreadsheet string to 2D array

Message 6 of 16
(322 Views)

I tried something like this, but I'm getting an error with the Scan From String block:

Ouinon_1-1748955609978.png

 

 

 

And I also tried this, but it only shows 0...

Ouinon_0-1748956454351.png

 

0 Kudos
Message 7 of 16
(305 Views)

@Ouinon wrote:

Ouinon_1-1748955609978.png

 

 

I tried something like this, but I'm getting an error with the Scan From String block.

 


In your first String to Array the Format just should be "%s" instead of 3x %f (you're grabbing the whole line as a string)

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 16
(294 Views)

Even after changing this parameter, I still get the error:
LabVIEW: (Hex 0x55) The scan failed. The input string does not contain data in the expected format.

0 Kudos
Message 9 of 16
(281 Views)

How does your input string look like? Can you give a verbatim example? Use probes and indicators to inspect the incoming data.

0 Kudos
Message 10 of 16
(267 Views)