Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# how do i compare two string that have matching letters but one has a whitespace

Here is my code below, how can I make the if return true as it currently skips over the if statement because of the string values has a space in it.

string instrucType = "FM";
string tenInstrucType = "FM ";
if (tenInstrucType.Equals(instrucType))
{
    blLandlordContactNumberHeader.Visible = true;
    lblLandlordContactNumber.Text = landlordData.LandlordContact.DefPhone;
    lblLandlordEmailHeader.Visible = true;
    lblLandlordEmail.Text = landlordData.LandlordContact.DefEmail;
}
like image 398
floormind Avatar asked Nov 16 '25 21:11

floormind


1 Answers

Use the Trim function:

if (tenInstrucType.Trim().Equals(instrucType.Trim()))

This will only trim from the ends though. If there is a possibility of a space in the middle, use the Replace.

like image 180
jpsnow72 Avatar answered Nov 19 '25 11:11

jpsnow72



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!