LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Range Parser Needed

Given a number, and a string of ranges (e.g. "..4,7,11,14-19, 33.."), I want to determine if the number is within the specified range.

Has anyone already built something like that?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 9
(491 Views)

This might help you partially

santo_13_0-1642028150054.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 9
(485 Views)

So we have two inputs (or controls):

 

  1. A number (Numeric datatype, I guess integer datatype from the example, but not expressively defined. Singed or unsigned? We might have ambiguities defining ranges for negative numbers since the "-" is overloaded).
  2. A string, defining the ranges.

And one output (boolean), where TRUE means that the number is part of the ranges.

 

  • Can we make any other assumptions (highest possible number, etc.).
  • Is speed important?
  • What are all possible special characters and their meaning (",", "-", "..", etc.)
  • Is the string input often the same with just the number changing (LUT candidate), or do both inputs change often?
  • Can we assume that the string input is always well formed, or should we check and possibly return an error? 

 

I can think of quite a few solutions. The best probably depends on the answers to the above..

0 Kudos
Message 3 of 9
(441 Views)

@altenbach wrote:

So we have two inputs (or controls):

 

  1. A number (Numeric datatype, I guess integer datatype from the example, but not expressively defined. Singed or unsigned? We might have ambiguities defining ranges for negative numbers since the "-" is overloaded).
  2. A string, defining the ranges.

And one output (boolean), where TRUE means that the number is part of the ranges.

 

  • Can we make any other assumptions (highest possible number, etc.).
  • Is speed important?
  • What are all possible special characters and their meaning (",", "-", "..", etc.)
  • Is the string input often the same with just the number changing (LUT candidate), or do both inputs change often?
  • Can we assume that the string input is always well formed, or should we check and possibly return an error? 

 

I can think of quite a few solutions. The best probably depends on the answers to the above..


  • In my specific case, the number will always be positive whole number <2100; but it would be nice to have a more general solution.
  • You're right about the "-".  I should eliminate it as a special character and only use "..".  The only other special character being the comma.
  • Both the string and number will change; but the function will usually be called only a few times per day.
  • It's OK to assume that the string is always well formed.
"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 9
(410 Views)

Do you have the ability to control the formatting of the ranges? Just having one modifier (e.g. 14-19, 33-, or 14..19, 33.. ) would make it super simple and therefore super fast.

 

Quick edit if not just do a string replace and that's first step then I would think.

Quick edit 2 it's early and I just restated something that's right above me, you're welcome.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 5 of 9
(398 Views)

@FireFist-Redhawk wrote:

Do you have the ability to control the formatting of the ranges? Just having one modifier (e.g. 14-19, 33-, or 14..19, 33.. ) would make it super simple and therefore super fast.

 

Quick edit if not just do a string replace and that's first step then I would think.

Quick edit 2 it's early and I just restated something that's right above me, you're welcome.


At this point, I can define the format of the ranges to be anything.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 9
(393 Views)

I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.

Spoiler
In Range.png

 

Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 7 of 9
(376 Views)

@FireFist-Redhawk wrote:

I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.

Spoiler
In Range.png

Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.


Nice.  Here's my variation of it (uses ".." instead of "-"; handles negative numbers; is malleable so it works with any numeric representation)

ir.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 8 of 9
(356 Views)

@paul_cardinale wrote:

@FireFist-Redhawk wrote:

I would use hyphen then as it's just one less character. This is what I came up with, feels pretty clean I think. Don't think I inlined it yet.

Spoiler
In Range.png

Edit: Edge case if only one range (no comma). And you can replace the hyphen with something else to get negative number functionality, but Match Pattern doesn't like the double dot it seems.


Nice.  Here's my variation of it (uses ".." instead of "-"; handles negative numbers; is malleable so it works with any numeric representation)

ir.png


Oops, there's a bug: If you wire a numeric array to "Number", it doesn't work properly.

Since I don't need it to work on arrays, I'll put fixing it onto the back burner.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 9
(315 Views)