I have two string variables and I want to compare them, how do I do this? I've been trying something like this (I have to use slice for my real code). Simplified Javascript Code: str1 = 'Hello World'; var1 = str1.slice(0,5); var2 = 'peaches'; if(var1 != var2) { //execute some code } Code (markup): Thanks! ~imozeb
Well... my code is slightly more complicated. About 200 lines of functions but the main problem is as stated above. It looks more like this. Javascript Code: check1 = function() { var2 = var1; if(var1 != var2) { //execute some code } } getcode = function() { str1 = xmlhttpget.responseText; //Could be about any 20 letter char plus 2 spaces (Hello World ) //delete 2 spaces var1 = str1.slice(0,5-2); } Code (markup): I checked the lengthes and they are the same, I also checked the output and it looks the same but when I compare them it does not work. Thanks! If it still works for you tell me and I'll try to show you the full code. ~imozeb
But if var2 = var1;, how can this work if(var1 != var2) { //execute some code } ?? I don't understand you.
Oh! Sorry, I was busy when I wrote that. This is what the code should look like: Javascript code: //name can be anything (it is an input text box) getname = function() { check1('world') } check1 = function(name) { //get input name var2 = name; //make sure name does not equal to the response text if(var1 != var2) { //if so execute some code } } //get responseText getcode = function() { str1 = xmlhttpget.responseText; //Could be about any 20 letter char plus 2 spaces (Hello World ) //delete 2 spaces var1 = str1.slice(0,5-2); } Code (markup):
I thought I tried that debug along with the .length debug to check for spaces but for some reason when I tried it again this time I found the error. There was a hidden space before one of the texts and the ending letter of one of the texts was chopped off. Thanks! ~imozeb