473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Multiple IF-statement conditions

132 100+
Hi there.

I need a sanity check here.

I have an array of strings and am running the following block of code in C#:

Expand|Select|Wrap|Line Numbers
  1. string[] cols = line1.Split(separators.ToCharArray());
  2.  
  3. if  ((cols[6] == "1") && (cols[23] == "Y") && (!(cols[20] == "STR REC ")))
  4. {
  5.   //Do something...
  6. }
When I debug this, the respective watch values are:

cols[6] = "1"
cols[23] = "\"Y\""
cols[20] = "\"RD REC\""

So I would have expected this to enter the body of the IF-statement and execute the respective code, but that isn't happening.

Hence can anybody see where my logic is going amiss please?

Thank you.

Mark :)
Dec 11 '08 #1
6 2325
nukefusion
221 Expert 100+
The only thing I can see at the moment is that your watch values for cols[23] and cols[20] have some quotation mark string literals in them that you're not testing for in your conditional statement.
Dec 11 '08 #2
E11esar
132 100+
Hi again.

I have tried amending the if-condition to look as follows:

Expand|Select|Wrap|Line Numbers
  1. if  ((cols[6] == "\"1\"") && (cols[23] == "\"Y\"") && (!(cols[20] == "\"STR REC \""))) 
  2.   //Do something... 
  3.  
  4.  
But still no joy when all conditions are met. Sorry for being so daft but is there anything else I can do to get the logic to work here please?

Thank you.

M :)
Dec 11 '08 #3
nukefusion
221 Expert 100+
Hi, no problem. What are the watch values when it's failing in this particular case?

I see you've added quotation mark literals for the check against cols[6] as well, although in the watch value in your first post, col[6] doesn't contain quotation marks. Did you mean to do that?

Even easier might be to just post exactly what you want the contents of cols 6, 20 and 23 to be in order for the condition to pass in a plain english sentence. I'll then help you to write the IF statement.
Dec 11 '08 #4
Plater
7,872 Expert 4TB
One might consider doing this:

Expand|Select|Wrap|Line Numbers
  1. bool a = (cols[6] == "1");
  2. bool b = (cols[23] == "Y");
  3. bool c = (cols[20] == "STR REC ");
  4. if  ( a && b && (!c)) 
  5.   //Do something... 
  6.  
And then you can see which watch value failes to bring it into the loop.

Also, for !(cols[20] == "STR REC "), why not just do this:
(cols[20] != "STR REC ");
Dec 11 '08 #5
E11esar
132 100+
Hi there.

No that is right with the cols[6] value being in quotes and the watch values are as stated.

In effect I have a CSV file and hence this is where all the quotes are coming from but again, I think I'm getting myself into a tizz here.

If I use a MessageBox to display the respective values then for a given example,

cols[6] = 1, cols[23] = "Y" and cols[20] = "STR REC".

Hopefully that clarifies matters..?

Thank you for your help.

M :)
Dec 11 '08 #6
E11esar
132 100+
Hi there.

I think I just solved it:

I have used the following line:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if  ((cols[6] == "1") && (cols[23] == "\"Y\"") && (!(cols[20] == "\"STR REC \"")))  
  3. {  
  4.   //Do something...  
  5. }  
  6.  
  7.  
  8.  
and this is now behaving as required.

Amazing how the simple things can throw you sometimes.

Thank you again for your help; I'm sure I'll be back again soon as I'd be lost without this excellent forum!

M :)
Dec 11 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
6
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.