LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan From String White Space

i all,

I'm trying to use Scan From String in order to parse some data coming in from UDP. 

Input String: ASCII [00 01 02 03 ... FF]

What I want: s[00 .. 30]  d[12], d[34], d[56] leftover s[37 38 39 ... FF]

 

 

ATTEMPT1

Format String:  %49s%2d%2d%2d

What I get: s[00-09]  RUNTIME ERROR!

 

 

 

ATTEMPT2

Format String:  %49[^]%2d%2d%2d

What I get: Only allows first output.  Will error out if I use any additional outputs from Scan From String

 

 

ATTEMPT3

Format String:  %49[^(0xFF)]%2d%2d%2d    Value in () is ASCII character FF.

What I get: s[00 .. 30]  d[12], d[34], d[56] leftover s[37 38 39 ... FF]


It appears as though when I use %##[^] it thinks I'm looking for the ENTIRE string so it will not let me add any more Formatting.  If I add a delimiter other than ^ it will run, and it will work presuming that character isn't within the first 49 characters... and I can't guarentee that it won't.

I'm aware I can parse my string using subsets and whatnot... but Scan From String is so elegant.  It would be great if %S allowed for white space... or if $##[^] would simply take the first ## characters and allow me to Format after that.

Is there a simple, elegant way to do this?  I wish my dataset was only 3-4 outputs. It'd be ideal if I could.  Thanks.

 

 

 

 

Edit:
It might be more helpful if I provide a less abstract example:

I have an ASCII Header (Finite Length String), a Sender IP (Finite Length String), a Timestamp, a Message ID (Finite Length Decimal), A Message in ASCII ( '1' actually means 0x31, not 0x01)  And for some ungodly reason... no delimiters.

So I was HOPING %##s%##s%<%H:%M:%s>t%##d   (With leftover string to be my message)  would work, but if any white space is contained within there... it messes up. 

0 Kudos
Message 1 of 7
(3,718 Views)

Can you provide a specific example instead of a less abstract example? 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 7
(3,700 Views)

Match Regular Expression.vi would probably be of better use than Scan From String in your case. Can you provide us with an example of a typical string you are receiving.

 

Ben64

0 Kudos
Message 3 of 7
(3,649 Views)

I cannot provide exact strings because the string is actually ASCII characters, most of which aren't displayable. 

 

I have a string where I have:
24 ASCII Characters representing 6x U32 Header Data

13 ASCII characters represening the sender IP (string)
12 ASCII Characters representing the name of the message (String)
12 ASCII Characters representing 3x U32 Data
12 ASCII Characters represneting the name of packet (String)
12 ASCII Characters representing 12x U8 Data
256 ASCII Characters represening 256x U8 Data
etc...

It would be ideal to simply Scan from the string and output the data with the appropriate data types already assigned instead of splitting string and type casting each individualy.  But if, for example, my header starts with an ASCII representation of a U32 of 2560(decimal) it would look like this:  [00][00][0A][00].  ASCII 0A is considered white space.  So my header would only contain 2 ASCII characters instead of the desired 24.

0 Kudos
Message 4 of 7
(3,634 Views)

Can you not post a picture of the text so we can see an example?  You'll have to help us help you.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 7
(3,615 Views)

Post an Example String, already, or better, post several example strings.  After you post them, describe how/where you want to parse them (I assume there are "obvious" breaks, and you want, for example, some of the characters returned as a string, some as numbers.  If so, how are we supposed to recognize when the Parse starts and stops?  Is it strictly according to "spacing", e.g. "The first 49 characters are a string, then the next two characters should be intrpreted as an integer, and the following two characters are another integer".  Note that this would imply that "1234" would be parsed as "12" and "34", whereas "12 34" would get parsed as "12" and "3".  Say clearly what you need and what you have.

 

Bob Schor

0 Kudos
Message 6 of 7
(3,600 Views)

@Dyskresiac wrote:

I cannot provide exact strings because the string is actually ASCII characters, most of which aren't displayable. 

[...]

Then, run your VI with an indicator on the wire containing the ASCII characters, copy that indicator into another VI, make it a control and set the funky data as the default value.  Post that VI (not a picture) along with what you need to get from it.

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

0 Kudos
Message 7 of 7
(3,572 Views)