-
I know how to do this in VB but not in VC++ :(
Code:
Select Case BookName
Case "VB"
'//Do what ever I need here
Case "VC"
'//Do what ever I need here
Case "Java"
'//Do what ever I need here
Case "Others"
'//Do what ever I need here
End Select
I try this in VC++, & it seem not work as what I expected.
Code:
switch (BookName)
{
case 'VB':
'//Do what ever I need here
break;
case 'VC':
'//Do what ever I need here
break;
case 'Java':
'//Do what ever I need here
break;
case 'Others':
'//Do what ever I need here
break;
}
-
You can't. Since strings in C are arrays, you can't compare them like that. You need a long string of else ifs.
-
The Switch statement can evaluate integer, long or char, but NOT variables (unlike the case statement in VB). Also, keep in mind that whichever case is evaluated to be true, the program will "jump" to that point AND CONTINUE TO EXECUTE ALL THE SUBSEQUENT CODES within the Switch statement (i.e. all the subsequent cases). If you don't want that to happen, you have to put a break after each case statement.
Hope this helps.
substring.
-
Oops, I see that you know how to use break. =) But again, you cannot use Switch on variables.
substring.
-
Apart from what's been said already, you don't use the apostrophe ( ' ) character to denote strings; they should be surrounded by speech marks - "this is a string". The apostrophes should be used when you want the code for a single character, which you are entering as a literal. So you might have
char continue = 'y';
or
char newline = '\n';