01-11-2022 10:40 AM
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.
01-11-2022 10:48 AM - edited 09-08-2024 08:50 AM
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!)
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?
01-12-2022 03:08 AM
Hi,
I tried this method but its not working for me.
01-12-2022 03:28 AM
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.
For serial communication not working:
01-12-2022 04:10 AM
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?
01-12-2022 04:45 AM
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.
01-12-2022 12:54 PM
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.)
01-13-2022 01:46 AM
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.
01-13-2022 02:20 AM
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.
01-13-2022 02:25 AM
Thanks.
Spreadsheet string to array and Scan from string are working for normal string but not in serial.I tried all the possible ways.