ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from String Error 85 does not recognize value as string

Solved!
Go to solution

I'm following this example to separate what's before the dot and after in a string:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YPlUCAW&l=en-US

I've tried to adapt it here, it works halfway, Labview separates decimal "7" before the dot and string "X34" after the dot. However, when I change my mask to "%s.%s", I expect to see string "7" and a string "X34", but I get error 85, "Scan failed. The input string does not contain data in the expected format". It doesn't seem to matter if I replace "7" with a string "ABC", I still get this error. I'm so curious why does this code works halfway?

Screenshot 2023-08-02 105726.png

Screenshot 2023-08-02 110529.png

 

0 Kudos
Message 1 of 7
(2,277 Views)
Solution
Accepted by John32d

The problem is that the first %s is grabbing everything and then there's nothing left for the '.' and second %s. Scan from string is a greedy operation. You'd be better off splitting off the '.' explicitly (if you're not expecting decimal values at all) with match pattern and a pattern string of '\.' and then you can take the before and after inputs.

~ Helping pave the path to long-term living and thriving in space. ~
0 Kudos
Message 2 of 7
(2,271 Views)

Obviously, it cannot tell where one string ends and the next begins. One possibility:

 

 

altenbach_0-1690989590631.png

 

 

0 Kudos
Message 3 of 7
(2,264 Views)

This solution kind of works, but it splits the string when it sees the first dot. Is there a way for it to split on the last dot?

0 Kudos
Message 4 of 7
(2,227 Views)

You need to use pattern matching or even regex. LabVIEW is not clairvoyant!

0 Kudos
Message 5 of 7
(2,221 Views)

You can do a match pattern telling it to grab a '.' and everything up to the end of the string that isn't a '.'. If it finds a second '.' it restarts the match there and keeps grabbing characters until it hits the end or finds another '.'. The pattern is \.[~\.]*$ and follows normal regex patterns you'd see for PCRE format except that within the [] the ~ is there instead of ^ in PCRE. If you use something like regex101.com you'll see the explanation using a ^ instead of ~ https://regex101.com/r/QXWxIr/1

IlluminatedG_0-1691006692144.png

 

~ Helping pave the path to long-term living and thriving in space. ~
Message 6 of 7
(2,180 Views)

Thank you, reversing the string and using matching pattern so it grabs the last entry only worked for me.

0 Kudos
Message 7 of 7
(2,095 Views)