LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing out non-numeric characters in a string

Solved!
Go to solution

Hello,

I am communicating to a robot from LabVIEW (2013) via sockets and TCP/IP. The robot is the server, and LV is the client.

I am starting with the target data in this format (in a string):

"[0~100~0]~[0.96593~-0.25882~0~0]~[1~0~0~0]~[150~50]"

[X,Y,Z],[Q1,Q2,Q3,Q4],[C1,C4,C6,Cx],[TCPVel,OrientVel] except replacing the "," (commas) with a "~" (tilde) because I am loading the target data in from a spreadsheet that is a comma delimited file.

In LV, I am taking that string, scanning from the string and splitting up the individual elements. I then output the single elements as single, 32-bit reals. I take each of these, and convert them individually back into a string, and then concatenate them and send them to the robot. The robot unpacks these raw bytes individually and converts them into a robot target (position in space).

I am trying (in LV) to check if the user sent a bad character (non-numeric character) in the target data. Example of this is:

[-50~-150~0]~[0.96593~-0.B2A5D882~0~0]~[1~-1~0~0]~[150~50]

Now, in LV, when I am scanning from the string, these bad character turns the whole element to zero, and any other elements afterwards to zero as well. See attached screen shot for similar example.

My question is, in my VI, can I parse out any non-numeric characters (that are inside the brackets and characters that are NOT a "~" (tilde))? That way, I can still get the numbers of that element and not have that element or the other elements turn to zero?

 

Thanks in advance for any help!

Sorry for the essay question 😛

SM

0 Kudos
Message 1 of 70
(5,276 Views)

This sounds like a job for Regular Expressions.  But I'm not an expert on them to be able to tell you what the string would like.

Message 2 of 70
(5,245 Views)

Well is there a way to like scan the string and if it contains non-numeric values in the brackets and/or in between the tilde's, just discard it and keep the number values?

Attached is a word document which is a list of all the possible bad inputs for the string.

I need to be able to parse out any of the bad data and keep the numeric values. Or at least alert the user that a bad string has been input. For instance if I input #1 from the attached document, that's a non-numeric character, but a non-numeric character is supposed to be there (a tile "~"). However, it's the incorrect non-numeric character. So at that point could I either replace that bad character with a tilde, or at least alert the user that bad string has been input?

 

Regular expression doesn't really help me much...

 

Thanks,

SM

0 Kudos
Message 3 of 70
(5,242 Views)

You also have periods (decimal delimiters) that you probably want to keep, right?

What about the lettter "E or e" as in 0.5e-1?

0 Kudos
Message 4 of 70
(5,234 Views)

Correct. I need the decimals and negative signs. But I believe that is all. I probably need to check also for 2 periods (1..234) or 2 negative signs (--123). There's just so many possiblities of bad inputs.... I think the "E" or exponential will be ok

Thanks,

SM

0 Kudos
Message 5 of 70
(5,230 Views)

@SteMob wrote:

Regular expression doesn't really help me much...

 



I think it will help you a lot.  Because it can include characters, exclude characters, and understands position withing the string and the difference between numeric and non-numeric.  It seems like your strings are pretty well defined used the tildes and brackets and is ideally suited for regular expressions so that you can find the bad characters and replace them with nothing.  The hard part is determining the correct regex string.  Others on the forum are regex wizards.  Me, I'm just beginning to study them.

0 Kudos
Message 6 of 70
(5,203 Views)

Oh ok, that makes sense. I guess I just didn't understand what that function did.

 

That being said, can somone with more experience with Regular Expression formatting help me or show me an example of something like this?

 

Thanks for the help,

SM

0 Kudos
Message 7 of 70
(5,200 Views)

I usually just pound my head against the wall until I come up with a RegEx expression that does the job.  😉

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 8 of 70
(5,180 Views)

Yes, that's what I have been doing for hours... Does anyone know how to write a format for Regular Expression for what I need?

 

Thanks for any help,

SM

0 Kudos
Message 9 of 70
(5,177 Views)

It all just seems way too fragile. What if the extra characters happen to be numeric? Maybe you also need to send a checksum or similar to validate the message.

0 Kudos
Message 10 of 70
(5,164 Views)