LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

scan from string

Solved!
Go to solution

Hi all,

 

I am trying to use the scan from string function for the string below.  I want to try tro commad as the delimiter and ignore the space.  I read the the scan from string function doesn't like space in the scan string.  I tried to get around it but I can't.  If I still want to use that function, how do I get aroun it?  Thanks!

 

Yik

 

 

RD-33-231 ,300274 ,         ,07.08.03

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 11
(3,756 Views)

Can you post a screenshot of your code? Into what part of the string are you interested in and into what data type do you want to format into?

0 Kudos
Message 2 of 11
(3,740 Views)

You can use the Search and Replace function to remove the spaces before using the scan from string function.

 

remove space.png

 

Ben64

0 Kudos
Message 3 of 11
(3,722 Views)

Try this:

 

 

 

You could also just use the Spreadsheet String to Array to get your self an array of 4 elements.

Message 4 of 11
(3,721 Views)

Hi all,

 

I looked at the input string in code view, and I realized that the space that I saw on normal display is actually not space, but they are \00.  Also, I need to parse out 3 items from the string, and they are RD-33-231, 300274, 07.08.03.  I want them all to be in string.

 

RD-33-231\00,300274\00\00,\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00,07.08.03

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 11
(3,706 Views)

Use a Match Pattern to find the comma and strip the whitespace.  You can wire the output of the Trim Whitespace to an indexing tunnel to build your array, but I'm using the variant to simplify cleaning out the instances of no data (between the second an third comma in your sample).  Using variant attributes this way will also keep the loop from recording duplicate entries, so don't use it if you need to capture repeated data.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 6 of 11
(3,676 Views)
Solution
Accepted by topic author jyang72211

Alternate method.

 

remove space 2.png

Message 7 of 11
(3,661 Views)

Hi Ben,

 

Can you explain \00*,\00*,*?

 

I understand how that work for what is after 300274.  However, it seems like a single /00, was matched and replaced by the comma as well.  How did that happen?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 8 of 11
(3,644 Views)

I'll let Ben give the explanation, but I'll provide a hint. 

 

The asterisk, in a Regular Expression, doesn't mean the same thing it does elswhere.  It's not a "wildcard" like in a Windows search, rather it "[r]epeats the previous item zero or more times. Greedy, so as many items as possible will be matched before trying permutations with [fewer] matches of the preceding item, up to the point where the preceding item is not matched at all." (from here)

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 9 of 11
(3,636 Views)

Well after tought the first \00* should be replaced by \00+ to avoid the useless situation of replacing a comma by a comma. So I will explain \00+,\00*,*

 

\00+, will match one or more \00 character followed by a comma (in RD-33-231\00,300274\00\00,\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00,07.08.03 it will match the first 2 red highlighted sequences and the green highlighted sequence).

 

If you only use this expression it will result in the following string: RD-33-231,300274,,07.08.03 after the search and replace function.

 

The second part of the regex is use to avoid the double comma in the resulting string \00*,* match 0 or more \00 followed by 0 or more comma. Adding this will make the second red sequence and the green sequence a single match.

 

\00+,\00*,* will match the 2 following sequences: RD-33-231\00,300274\00\00,\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00,07.08.03

It will result in the following string: RD-33-231,300274,07.08.03 after the search and replace function.

 

Ben64

Message 10 of 11
(3,627 Views)