Alright, so basically, I'm trimming a string then making it lowercase. The lowercase part works perfectly well, but the sentence doesn't get trimmed. Any clue?
var result12 = TrimTheSentence(" John. Doe@ gmaiL . cOm");
//the method is
public static string TrimTheSentence(string givenString)
{
givenString = givenString.Trim();
return givenString.ToLower();
This is what you are looking for, you could shorten your method to just one line:
return givenString.Replace(" ", "").ToLower();
Trim()
removes blank spaces from front and end of the string. It will not remove spaces that are in the string.
Examples:
" Test String".Trim(); //Output: "Test String", it will remove only the leading spaces, but not the space between Test and String.
" Test String ".Trim(); //Output: "Test String", it will remove leading and trailing spaces.
MSDN link: http://msdn.microsoft.com/en-us/library/system.string.trim.aspx
Trim removes spaces from the start/end, not from the entire string. Try:
return givenString.Replace(" ", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With