08-02-2023 10:06 AM
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?
Solved! Go to Solution.
08-02-2023 10:16 AM
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.
08-02-2023 10:20 AM
Obviously, it cannot tell where one string ends and the next begins. One possibility:
08-02-2023 11:04 AM
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?
08-02-2023 11:07 AM
You need to use pattern matching or even regex. LabVIEW is not clairvoyant!
08-02-2023 03:05 PM - edited 08-02-2023 03:09 PM
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
08-08-2023 07:44 AM
Thank you, reversing the string and using matching pattern so it grabs the last entry only worked for me.