0

Can "if" use for words?

2nd Mar 2017, 5:12 AM
wahyudi
wahyudi - avatar
3 Respostas
+ 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!");
2nd Mar 2017, 10:45 AM
visph
visph - avatar
- 1
like what? give any example what you want to say
2nd Mar 2017, 5:35 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
- 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 .
2nd Mar 2017, 10:04 AM
handerson scott
handerson scott - avatar