LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to split a string on the basis of space in labview.

Hello everyone,

 

I wanted to split a string eg:  (84 228) on the basis of space.I tried search and split and  match patterns but I am unable to do it.The numbers will always be different this is just a example.But the numbers must be always split when there is a space.

 

Thanks in advance.

 

0 Kudos
Message 1 of 17
(5,633 Views)

There are plenty of possibilities. Do you want the output as string or as numeric datatype?

 

Are there only two numbers of could there be more?. You could just use "array to spreadsheet string" with a 1D array of integer as type and space as delimiter. This will give you an integer array containing all numbers.

 

If there are always exactly two numbers, use "match pattern" with a space as pattern. This will give you the numbers as strings. Did you read the help, which tells you to define a space as "\s"? (still, even a plain space character will work!)

 

altenbach_0-1641920036978.png

 

altenbach_0-1641920444434.png

 

 

 

Could it be that your "space" is actually something else, e.g. a "tab"? Can you look at the string in \-codes display to be sure?

Message 2 of 17
(5,630 Views)

Hi,

I tried this method but its not working for me.

Deepti_Singh_0-1641978503065.png

 

0 Kudos
Message 3 of 17
(5,566 Views)

Its working fo me.Thanks.I have more question.I am basically receiving these values via serial communication.This is working for me for normal string but when I am trying in serial communuication it is not showing anything.Thanks for your help.

 

For normal string working.

Deepti_Singh_0-1641979630111.png

 

 

For serial communication not working:

Deepti_Singh_1-1641979706470.png

 

0 Kudos
Message 4 of 17
(5,560 Views)

Are you sure that what you get from serial communication is a "real" string with numbers?

By using VISA for the serial communcation it gives a string in Ascii format that you can displaying as Hexadecimal and in that case this space is not a real one. We cannot say at 100% sure as you gave only images, not VI.

 

Could you please give more details or even better a VI to test it?

0 Kudos
Message 5 of 17
(5,552 Views)

It does not work for serial comm because there is a space before the first number. You must get rid of this space before using Search Pattern, for example using the Trim Whitespace function from the String palette.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 17
(5,543 Views)

I think the space used to be considered as part of the number, but that changed around LV 2015.  it was undocumented as far as I know, but even though it broke my code, I call it a bug fix.  (I was lazy and knowingly didn't scrape of the leading space because "it worked just fine".  That'll teach me to take shortcuts.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 17
(5,511 Views)

I used Trim Whitespace to delete the space at the start and end.I tried  Match pattern and spreadsheet string to array and scan from string but nothing is working in Serial communication I finally used String Subset.I dont know why nothing else is working for Serial.

 

Deepti_Singh_0-1642059943570.png

 

0 Kudos
Message 8 of 17
(5,483 Views)

This is not good for you, since both Spreadsheet string to array and Scan from string work if properly used.

I suggest you to make an effort to understand. And be more tidy in coding.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 9 of 17
(5,476 Views)

Thanks.

 

Spreadsheet string to array and Scan from string are working for normal string but not in serial.I tried all the possible ways.

 

Deepti_Singh_0-1642062289146.png

 

0 Kudos
Message 10 of 17
(5,473 Views)