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.
JavaScript

Avatar of undefined
Last Comment
geordie007

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zvonko

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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>
Your help has saved me hundreds of hours of internet surfing.
fblack61