LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question mark in pattern matching

Solved!
Go to solution

Apparently, we all need to read the help document...

The Match Pattern uses a subset of the Regular Expression syntax.  Not seeing the ? in the list of those supported.  And I am getting some conflicting results.  For instance, Use "Serial?\nblah" with \ codes for the string display and ? for the regular expression, I actually get "\nblah" as the after substring.  But search for Serial?\n and it can't find it.  Anyways, go reading the help and it clearly states to put special characters in brackets.  So the proper search should be "Serial[?]\n".


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 11 of 19
(1,653 Views)

The brackets are use for character classes and special characters acts differently when inside a character class. In this case [?] matches "?". Using the \ escape character gives the same result.

 

In the Match Pattern Function help file the is a green link to special characters, you will find ? listed there.

 

Ben64

0 Kudos
Message 12 of 19
(1,648 Views)

Thank you for all the replies, guys.

 

ben64's suggestion solved the question mark issue! On the other hand, I still want to optimize the code!

 

1. I have replaced the while loop with a for loop (see image below).

 

2. Removing the whitespace is tricky! It seems that the output from the small while loop is an array of strings. There is an auto-indexed tunnel on the right side of the while loop.

 

3. Regarding the serial port, the problem is that sometimes the serial device will not be connected. So the program will crash by trying to open a COM port that does not exist.

 

I would appreciate your input.

while to for loop.png

0 Kudos
Message 13 of 19
(1,629 Views)

I would suggest a class. You have a loop with a bunch of shift registers and this screams out to replace them with private data entries, and a single (or two, for errors) shift register. 

 

This will probably also fit more easily around using a bunch of subVIs to clear up the bazillion wires you have everywhere and the large amount of space used by Bundle by Name nodes or similar.

 

Regarding the whitespace loop, you can use the same function Crossrulez already mentioned in (I think) a different context to do the same, using '\s' as a delimiter. I do wonder if you can't simplify further though - it seems the handling of the array of strings is similar in many cases and might profit from some further changes. Below is a like for like replacement (I think):

whitespaceReplacement.png

(the '\s' constant is in '\' representation - it is a space character)


GCentral
Message 14 of 19
(1,617 Views)

Actually, on a further note, of the 7(!!) shift registers at the bottom of the loop, only 'Time Array' is changed (in the 'transfer' case). You don't need them to be in shift registers if you're only going to read constant values - just make them a normal tunnel and you can remove the 7 wires going across for no reason in half of the cases...

This is completely not true. Sorry - I missed the write cases under the mountains of wire!


GCentral
0 Kudos
Message 15 of 19
(1,615 Views)

cbutcher, I need two string outputs (command running, first element of command) and one string array output (rest of command).

 

I attempted a first optimization, using the spreadsheet to array function, and managed to get rid of the small WHILE loop. What do you guys think?

 

I do not know how to tackle the issue with the serial port opening and closing all the time. Concerning the .txt file removal, the strip path function is not exactly what I want, as it not only removes the extension but the name of the file as well, leaving only the folder path.

 

spreadsheet to array functions.png

0 Kudos
Message 16 of 19
(1,594 Views)

Three very quick comments:

  • The size of the array of strings that you pass to the spreadsheet function is irrelevant - your comment suggests that it limits the number of arguments, but only the type is considered.
  • If you want to take the filename without the extension, there is a built-in function under the 'Advanced File Functions' palette named Get File Extension which has an output labelled 'filename without extension'. However, double-clicking it to open the VI shows the methods lying beneath - it just uses the Strip Path (taking the filename string output, not the top path output) and then does something similar to what you already have. None-the-less, it might make your diagram clearer to read, so you can take a look.
  • Rather than using an Index Array and an Array Subset function, you can use Delete From Array and use both outputs, deleting the first element. Then the deleted portion is the first element, and the remaining array is the rest. If you don't  want two array outputs (you don't!) then don't wire the 'length' input - it will delete only one element if it is unwired.

GCentral
Message 17 of 19
(1,581 Views)

Thanks, cbutcher. I implemented the changes. However, I disagree with your first point. Both the type and the size matter. I tested it and it is also mentioned in the context help.

0 Kudos
Message 18 of 19
(1,566 Views)

I see only 'dimension and representation of array type' - no mention of size. Although it's certainly possible that I'm completely wrong, I can't imagine you'd need to initialize an array of ... many elements in order to read the values from a spreadsheet - that would seem pretty brittle and frustrating to me.


GCentral
0 Kudos
Message 19 of 19
(1,561 Views)