I have an ajax script that calls a php file.
The php file echos \"yes\" or \"no\", I want to use the strings to do logical comparisons.
In the javascript,
I know you asked about doing the comparison without regexes, but given the conditions you mentioned above, that's going to be a very quick and effective way to get your answer, and won't necessarily perturb any other processing.
var trimmedResponse = responseText.replace(/^\s*/,'').replace(/\s*$/,'').toLowerCase();
if (trimmedResponse == 'yes') {
// do your 'yes' case
} else if (trimmedResponse == 'no') {
// do your 'no' case
} else {
// do your 'none of the above' case
}
That's going to trim off leading white space, trailing white space (including the CR/LF combo), and convert to lower case just for comparison.