0
Can "if" use for words?
3 Answers
+ 3
@handerson scott:
You luckily right, as the OP ask for JS, not for C++ ;)
... in JS:
var s1 = "A test sentence";
var s2 = "A test sentence";
if (s1==s2)
alert("equals!");
else
alert("not equals!");
- 1
like what?
give any example what you want to say
- 1
Yes it can be used to compare two string , for example :
Comparing two string using strcmp :
if ( strcmp ( s1, s2 ))
The strcmp function compare two array s1 , s2 containing the string and return 0 if they are equal or return a nonzero value if not equal.
For example :
char s1 [80] = "String" ;
char s2 [80] = "String" ;
if ( !strcmp ( s1 , s2 ))
cout << "They are equal ! " ;
else
cout << "They are not equal " ;
Note : The ! inverts the value .