Scan string
I'm trying to scan one long string and the length may vary. I'm trying to display each character. for example.
Example.
,,,,,,,,,,,,,,,,,*1E if they are 2 commas back to back then stop the scan.
04,05,08,10,11,,*1E In this case i would like to first scan the string from left to right and display the numbers before the comma as long as there isn't 2 commas back to back
04,05,08,,,,,,,,,*E In this case I would like to scan the string from left to right and display the numbers before the comma 04 and 05 and 08 and stop there are 2 commas back to back.
Solved!
Go to Solution.
Depending upon what you are going to be doing with the data next, use the spreadsheet string to array function to turn the string into an array of strings and then search the resulting array for the first element containing a null string. Then pass everything before the null element to the function for turning a numeric string into a number and (hey, presto) you have an array of numbers.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
Similar Messages
-
VISA and Scan string for tokens
Hi there,
I am currently developing a piece of software which needs to take in data from an Arduino board via the serial port and parse the input accordingly.
I have the 2 pieces of code working perfectly well separately, but I can not seem to figure out why they are not functioning properly together.
Just now, the input is being retrieved fine and passed into the Scan string for tokens method, but it is not being split on the tokens, it is just outputting the string as a whole.
The input is in the form of 1:0 2:0 3:1 etc. so I am trying to split it on any spaces found. If I attach a string to the Scan strings for tokens it works fine, just not when I am attaching the data from the serial port to it.
Any help would be appreciated.
Attachments:
input manipulation.vi 16 KBHi,
In the output which you are getting from the serial port, is there space between 1:0 and 2:0 and 3:1? If there is no space between them, then it wont be able to scan for tokens and will output the whole string. I don't have the hardware here and so don't know what exactly is the output which you are receiving. Try to see in the read buffer indicator whether the tokens are seperated by a space or not.
I have attached your vi after adding a small part in it. If the problem is with the spacing then this will work fine for 1:0 2:0 3:1.
Regards,
Nitzz
(Give kudos to good Answers , Mark it as a Solution if your problem is Solved)
Attachments:
input manipulation.vi 18 KB -
Scan String Token Problem with leading Tokens
Hi, I'm using the scan string for token to read in a string of tokens that contain a leading "*" char in front of each string and terminates when the token index = -2. This works great if I have say *12345*1234 and so forth, but if there is bad data, say 1234 without the leading "*" in front, the token index return value is still -1 and it returns data which I read in thinking it found the "*". Maybe I shouldn't use the string for token function since it's probably just designed for ending tokens and not data with leading tokens. Is there a way to make this work properly or should I use another method to search for leading tokens in a string?
Thanks.
Solved!
Go to Solution.Here. Try this one. It does the same thing and uses exposed functions.
The string functions look for something to mark the end of a string. All languages that I know of do this. So, like I said, remove the first element. I recommend the Subarray function with the index set to 1 and length unwired.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Parse Message.png 10 KB -
Is Scan String for Tokens documented correctly?
I attempted to parse the following string using " as the only delimiter (no operators):
this "is a test" for "you and me"
The first call produced: "this " w/o the quotes.
I expected "is a test" w/o the quotes.
The documentation says the function will return tokens "surrounded by" delimiters. If this is not a bug, I think the documentation should be improved.
W. BrownThank you for commenting on the Scan String for Tokens documentation. We will look into this issue and try to make the documentation more clear about how this function works.
We're constantly striving to improve the documentation, so any specific suggestions you have are welcome. In the future, please send any comments on National Instruments documentation to [email protected] so we can address your concerns in a timely matter.
Kelly Holmes
LabVIEW Documentation Team
Kelly H
LabVIEW Documentation
National Instruments -
Can anyone help me out on how to detect a new line using the scan string for tokens function? I am using the "\n" delimiter but it is not working
Syntyche wrote:
I opened a text file and display it on string indicator. The following is an example of my text file
START
SETMASS 5
WAIT 5s
SETVELOCITY 10
WAIT 3s
END
So what I want to do is to obtain the string line by line.
I am thinking I can use scan string for tokens with delimeter \n.
So if i put this in while loop, in the first iteration, I would want the ouput to be START
Second iteration: SETMASS 5
Third iteration WAIT 5s. and etc....
In C programming i believe this can be done by using strtok. So i want to have a similar function.
See James' post above, which is what I was hinting at when I said it could be less complicated. And that's why I asked WHAT you were trying to do, instead of HOW. In this latest post, you show WHAT you wanted to do, and doing that in the first place would have made the thread a lot shorter. -
"Scan String For Tokens" weird behaviour
I am trying to carry out the simple task of getting a string with
comma delimiters and produce a string_array with the values in between
the commas; this would simplify calling the different parts of the
string.
Example:
INPUT: this,is,an,example
OUTPUT: this|is|an|example (this would be an array of strings)
Using a while loop with the two VI "Scan String For Tokens" and
"Insert to array" should be enough to carry this task. I started
using a FOR loop as the number of tokens I´ll be using is fixed.
However I wanted to make the subVI more general by allowing any
#tokens in the input string and using the token index with a WHILE
loop to do this. The "token index" output from the "Scan String For
Tokens" is said to be use
d in a while loop to process the whole
string.
However,I´m getting -1 as an output even if I´ve got more tokens left
and the while loop therefore exits.
What am I doing wrong?
Should I use -2 as the comparison to decide whether I´m at hte end or
not of the string?
Cheers and TIACheck the offset for -1, not the token index. (See attached image). If course if this is a multiline string, the you also need /n etc as delimiter.
If the string ends in a delimiter, you need to clip the last array element. I usually use "reshape array" with the output from [n] as input.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
ScanForTokens.gif 17 KB -
ScanFile with scanning string modifier %s[in]
For skipping over non-numeric characters by reading ASCII files I used to write, e.g.
ScanFile (fhandle, "%s[i8]>%f", &x);
This method works well with CVI 5.0 to 8.11 but no more with CVI 2009 and 2010. I have modified my old code using other scanning string modifiers:
ScanFile (fhandle, "%s>%s[dt#]%f", &x); or
ScanFile (fhandle, "%s>R1= %f", &x);
The first one does not work with a string like “R1=200”. The second requires the exact string and is more inconvenient. Although the modified code works well now with CVI 2009, I would like to know why the scanning string modifier [in] does not work with CVI 2009 and 2010. Is there something wrong in my code, is it a feature of the new versions of CVI or is it a bug? How about CVI 2013?Thank you very much for your reply.
I would not use "%s[i8]>%f" to read the number 200 in string "R1=200". I just wanted to take this string as an example to say that I couldn't simply change all of "%s[in]>%f"s in my code to “%s>%s[dt#]%f"s, somewhere I had to use a quite inconvenient "%s>R1= %f". Therefore I do hope that "%s[in]>%f" works by a new version of CVI.
In my code I use a lot of Scan (string, "%s[in]>%f", &x) and all of them work always correctly, also with CVI 2009-2010. But none of ScanFile (fhandle, "%s[in]>%f", &x) works with my CVI 2009, they work only with earlier versions.. That’s very strange to me as I couldn't find in the documentation/Help of CVI 2009-2010 a description that "%s[in]>%f" should not be used with the ScanFile function,
My further tests showed that this problem seems to be related to CVI Run-time. By reading the same ASCII file, the same executable created by CVI 8.11 works with CVI Run-time 8.1 but does not with Run-time versions 9.0 to 10.0.1.419. -
Labview novice with a question about scanning strings
Hello, I'm a research assistant tasked with taking data received via TCP-IP and plotting it. I've had a couple of problems, probably because I've never used Labview before.
The data is sent in sets of six values separated using semicolons as delimiters, for example
"0.086842;0.00020341;0.00039838;-0.14057;-0.12614;-0.1327;" is one such data set
Receiving these strings through TCP connection is working just fine, however I just noticed that after passing a string such as my example into a 'Scan String for Tokens' block, the negative signs are dropped from the latter three values. I assumed it has something with setting '-' as an operator, but simply wiring negative sign in as an operator didn't change anything. I know there has to be a way to retain my negative signs, but I can't figure it.Is this what you need?
Attachments:
SNAG-002.jpg 91 KB
SNAG-003.jpg 20 KB -
Missing HEX characters from scanned string
Hi everyone,
I have a program which scans a continuous string of serial data which is divided into header, data and checksum. I have replaced the serial part of my code with a simple string input to simulate the data input for testing and as in the diagram below you can see 0A, 0C and 0D are missing and I can't figure out why. Currently it is an exercise to parse out all the data I need for a data aquisition system. If anyone can help me out with this I would greatly appreciate it. This was in a different thread but it has dissapeared into the ether. Here is the picture illustrating the problem.
Thanks again
Stirling
Message Edited by stirlsilver on 04-09-2007 06:17 PM
Attachments:
Serial read v1.2.vi 85 KBYou are doing all this way too complicated. There is absolutely no need to use "scan from string" to simply chop up a string into parts. Use string subset instead (in a loop).
You also have way too much duplicate code. You can operate on arrays directly and use array indicators for the channels. This reduces the complexity of your diagram 10 fold!!!
I don't have your serial hardware, but attached is a small code fragment (LV 8.0) that seems to do about the same thing with your string using 10% of your code. Modify as needed. Let me know if anything is not clear.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Serial_read_v1.2MOD.vi 24 KB -
Scan string for computer user name
Good morning NI Forums,
I need direction on a file path scan. I'm trying to get to the user name on any system, primarily XP or 7. I'd like to compare the user name from the "Get System Directory" VI with a constant user name.This way I can pass that to a case structure and close LabVIEW if the computer is logged into the wrong user (there are network read/write permissions which is why I need to control where the program isrun from). Any suggestions for the format string constant or maybe a better mouse trap?
I've attached my VI for reference.
Thanks!
Tyler C. | Certified LabVIEW Associate Developer
Solved!
Go to Solution.
Attachments:
Check Computer Name.vi 12 KBI don't have LV2011.
Have you seen this Knowledgebase article?
Programmatically Retrieving a Windows User Name in LabVIEW
Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.
"You are what you don't automate"
Inplaceness is synonymous with insidiousness -
Hi,
I have a multi lined string and want to put it as list into a listbox (i
did it with a for loop and the "i"attached to the line index of the
"pick line" vi) but now a have let my for loop know how many rounds it
must do! How can scan a multi lined strings for "number of lines"?
Regards ThijsThijs,
Use the "Spreadsheet String to Array" function (in string functions). Wire
it as follows:
format string: string constant containing "%s"
spreadsheet string: your string
array type: (empty) array string constant
delimiter: string constant containing enter ("\n" with string in code
display mode)
The output "spreadsheet" is an array with strings that can be wired to the
attribute node of the listbox.
Important notice: \n is not the same as \r ! If your string comes from a
..txt file, this can cause unexpected results!
Regards,
Wiebe Walstra.
AIR technical Automation.
By the way, Thijs. If your in the Nederlands, maybe you'd like to visit our
annual LabVIEW meeting, PierVIEW. This also applies to the rest of the
group. Check out www.air.nl, and follo
w PierVIEW 2001.
AIR technical Automation
www.air.nl
"Thijs Boeree" wrote in message
news:[email protected]..
Hi,
I have a multi lined string and want to put it as list into a listbox (i
did it with a for loop and the "i"attached to the line index of the
"pick line" vi) but now a have let my for loop know how many rounds it
must do! How can scan a multi lined strings for "number of lines"?
Regards Thijs -
Scanning string for uppercase letters
Hey guys just a simple question that i'm stuck on. im working on a program and i need to scan a string to see if it has uppercase letters. the only thing i know about that even seems helpful is isUppercase but im not sure how i'd use it. i'm basically generating a sentence form categories which are in uppercase and need to expand the sentence as long as there are categories left. id appreciate any help! Thanks!
String ts = "i Have a capital";
boolean hc = false;
for (int i=0; i < ts.length(); i++)
if (Character.isUpperCase(ts.charAt(i)))
hc = true;
break;
System.out.println(""+hc); -
I got an error when I run the attached code. When I get rid o the comma after the last %s, the error would be gone though. What's going on?
yik
Kudos and Accepted as Solution are welcome!
Attachments:
Untitled 4.vi 8 KB%s matches a string up to the next space, I believe. Since a comma is a valid character, %s is matching "C,". If you specify %1S then you can keep the comma because it will match only 1 character, and the comma will not be part of the match.
Wow, I'm actually learning this regular expression nightmare.
- tbob
Inventor of the WORM Global -
Scan from string, inserting . into a string
Hellow LV'ers
Simplified Example
I have a string with 3 digits e.g. input 789
I would like to use scan string to place a "." between the digits.
input 789 output 7.8.9
How do I set up the scan string to do this?
Thanks
Solved!
Go to Solution.Of course a general solution needs to be more scalable. I don't think we can assume that there are always exactly three numbers, because this was only given as a "simplified example".
Here is a solution that works for any length string (containing decimal digits exclusively)
(of course you need to ensure that the input is sane and does not contain any illegal characters. not shown, but look at lexical class)
LabVIEW Champion . Do more with less code and in less time .
Attachments:
interlacePeriods.PNG 6 KB -
OK I have been working with LabVIEW for many years and I have never understood the Scan strings for Tolkens.
Attached is what I expect, and what I am getting. Please set me strait once and for all.
Dan
Solved!
Go to Solution.
Attachments:
Scan string for tokens.vi 6 KBFirst of all, you're looking for the output from the wrong place. "String out" is an unmodified copy of the input string.
"Token out" is the response you're looking for.
The first iteration will find your starting " as adelimiter and deliver the part of the string up to but not including the " character. The second time you call the function (wiring through the returned index from the first run) it will give you the text between the first and second " which is exactly what you're looking for.
Shane.
PS My first Snippet!
Say hello to my little friend.
RFC 2323 FHE-Compliant
Maybe you are looking for
-
I have iphoto on my apple airwave. It is needing upated, but I am unable to update due to my exhusband. It was purchased under his itunes account. I can no longer even see my pics. What do I do.
-
Java and Display Issues in Plus
Hi everyone Please reply whether you have or have not seen any of the following: I'm working on a client site where we have some machines working just fine and others are giving corbaserver errors. Copying data from a worksheet into Excel using CTRL-
-
Prevent applicatio​n from unloading dll
Hi I have created an application that is made up of primarily two vi's, with one calling the other. The second vi, or the one that is called in turn calls/loads a dll. Now my problem is that before creating an application my vi's worked great since
-
I would like to have my bookmarks listed in the order of when I bookmarked them instead of in alphabetic order. How can I do that?
-
Hi! First, I want to tell you that I'm Belgian so I don't speak well english but I'm going to try to explain you my problem. I bought an iMac 27" c2d HD4850 in november. Since, I d'ont succeed to install windows with bootcamp. In fact, I've Installed