The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Case Structures & Strings

SercoSteveB
Active Participant

What are the contents of String Out following execution of the VI?

Case Structure String Ranges.png

Here is the only hidden case of the Case Structure.

Case Strucutre String Ranges.bmp

a) another case Structure expression question Requiring an Answer

b) another an Answer

c) Structure Requiring Answer

d) another Structure Requiring an Answer

Comments
crossrulz
Knight of NI

D

Wow, Steve.  You are getting vicious here.  The key here is that lower case letters are farther down the ACSII table than capital letters.


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
ambaum01
Member

d

Aaron M. Baumer
SercoSteveB
Active Participant

.  Up until yesterday I had never used Case Structures with strings for anything other than with complete matches (no range type expressions). The capability is cool (ish) but I am not sure I like it from a Readability and Maintainability standpoint?

SercoSteveB
Active Participant

...and another thing; it is sooooo easy to type in "A..c"; giving a completely different result.

NOTE.  You have to type the quotes, if you just type A..c LabVIEW autocorrects to "A".."c".

MrStevenUND
Member

D

First thing I did was look up the ASCII table to make sure lowercase came after uppercase.  Like you, Steve, I have only used the case structure with strings to perform full matches. 

Interesting thing is if you Right Click on the case structure, and check "Case Insensitive Match", It will only output "another an Answer".  So watch your options...

Steve,  I'm assumign the "2009" on the snippet indicates you are using LV2009.  Why aren't you using the latest and greatest 2012?

RAMESHB
Member

D

PBJ1
Member

D

and very vcious indeed.  Is the case structure just concerned with the first letter?

crossrulz
Knight of NI

As written, yes.  But you could have weird combinations like "cat..dog".  In this example "car" would not be included, but "catch" would.


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
nmpundlik
Member

D

SercoSteveB
Active Participant

@mrstevenund. Yep using LV2009 to create the snippets.  I have other machines with later versions of LabVIEW installed, it just happens that the machine I have connected to the internet has that version on.

Neelamma
Member

Answer is "D"

SercoSteveB
Active Participant

Answer 😧  Nice one crossrulz, ambaum01, MrStevenUND, RAMESHB, PBJ1, nmpundlik & Neelamma.

A variation on the theme of yesterdays question to highlight with case sensitive matches (thanks MrStevenUND) that the ASCII character set (Upper Case followed by Lower Case thanks crossrulz) defines the range.

GayatriT
Member

Ans is D

adiveppa
Member

Ans is D

AmarMakana
Member

Mr. Steve, I thought "case" would also have been concatenated.. because its mentioned "A".."c" there.. why isn't it concatenated? I partially understood your explanatoin answer, but could you be more clear? Thanks.

Amar.

crossrulz
Knight of NI

AmarMakana wrote:


                       

Mr. Steve, I thought "case" would also have been concatenated.. because its mentioned "A".."c" there.. why isn't it concatenated? I partially understood your explanatoin answer, but could you be more clear? Thanks.

Amar.


                   

I'm not sure what you mean by being concatenated.  The .. defines a range.  This range is based on the ASCII value (look up an ASCII table to understand the values better).  Any letters in a string after the defined letters do not matter here.

Oh, I should probably also mention that there is an option with the case structure to be "case insensitive".  If you have this on, then upper vs lower case is NULL and void.


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
SercoSteveB
Active Participant

Mr. Steve, I thought "case" would also have been concatenated.. because its mentioned "A".."c" there.. why isn't it concatenated? I partially understood your explanatoin answer, but could you be more clear? Thanks.

Amar.

Hi Amar

I think I understand what you mean.  Do you mean why does the String Case structure range definition behave differently to a numeric range case structure definition?

Consider the following

Case Structure Ranges.png

For both Case Structures; only the Default case is hidden which does nothing (no wiring)

After you run this VI 'String' = <empty string> (the string case structure has executed the Default Case) and 'Numeric' = 3 (the numeric case structure has executed the Case shown).

Any further thoughts anyone?

LordNobady
Member

I think it might be to "c" instead of including "c" to prevend confusion about if "ca" is part of it.


Learning LabVIEW since January 2013
AmarMakana
Member

Mr. Steve,

Yeah got a similar idea after seeing your reply snippet. Just see, this is what came up when I ran this VI. Also, when highlighted execution for your question snippet, "case" string when passed, the case structure executed Default case code. I thought "c" being the last in the range for that case, it isn't executed as true (corresponding "A".."c" case). But it returned the 'c' as the 'String' when I ran your reply snippet (recreated as mine is LV 2010). Why it happened so?

String Numeric and Case Structure.png

Strange output 1.png

AmarMakana
Member

Hi, in Mr. Steve's question snippet, the alphabet "c" is lower case. Not upper case, just see once. Then when "c" is compared with "case"  string (I understand that it is looked up by ASCII values and alphabets after the first one doesn't matter and keeping in mind the upper case and lower case string issue), the case should return true, meaning execute that case right?

SercoSteveB
Active Participant

AmarMakana wrote:

Strange output 1.png

Not sure how you got LabVIEW to do this.  I dropped your snippet into LV2012 and got the same results as my previous post (i.e. default case execution for 'c'.)

AmarMakana
Member

mmm, thats strange!! I should look closely whats happening.

SUYAM
Member

why case "c" not included pls anyone help me

crossrulz
Knight of NI

When dealing with strings and case structures, the final item in the range is NOT inclusive.  Therefore "c" would be be a match.


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
SUYAM
Member

thank you so much crossrulz

debapriya_maji
Member

Hi,

  For numeric range like 1..5, it is a close interval [1,5]. That is it includes both 1 and 5 in the range. Then, Why does not it include 'c' in the range A..c

crossrulz
Knight of NI

If the range was A..c, then would "cat" fit in the range?  It would not, even with 'c' being inclusive.  I think NI was trying to avoid this type of confusion by making it non-inclusive.


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
debapriya_maji
Member

Hi,

  Another couple of doubt: 

     1. What does the range “A..c ” means?

       2.With the range specified as "aaa..ccc", it should include 'bbb' in the range. However, the default case is being executed for 'bbb'. Why is it?

debapriya_maji
Member

What does "A..c" means?

crossrulz
Knight of NI

1. "A".."c" will cover all strings that start with any capital letter and any string that starts with "a" or "b".  Or, back to your original question, it will be [A,c)

2. "aaa..ccc" is a specific string.  Your range should be "aaa".."ccc".


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
debapriya_maji
Member

With “aaa..ccc” as range, the string ‘bbb’ executes the default case.

crossrulz
Knight of NI

debapriya_maji wrote:


                       

With “aaa..ccc” as range, the string ‘bbb’ executes the default case.


                   

Watch your quotes very closely.  "aaa..ccc" is not a range.  It is a very specific string.  "aaa".."ccc" is a range.


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
debapriya_maji
Member

I got it man. Thanks a lot.

chikare
Member

I was unaware of the ASCII tables, SercoSteveB thank you very much for show casing this.