Link to home
Start Free TrialLog in
Avatar of ICPooreman
ICPooreman

asked on

compare strings ignore \n and whitespace

I want to compare two strings like below.

string test = "This is a Test";
string test2 = "\n       \n           \n This is a Test                 \n"

if(test == test2){
   //do something
}

I'm assuming I can strip the newlines and whitespace somehow and this will work but I'm not sure.
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geordie007
geordie007


like this?:

<script>
      
var test = "This is a Test";
var test2 = "\n       \n           \n This is a Test                 \n";

if(test.replace(/\s+/g,'') == test2.replace(/\s+/g,'')){
   alert("matches");
}      

</script>