How do you compare the last character of a string with some letter or accent

0

I need to compare the last letter of a String with an interrogation accent.

I've already done it and the code works, except that I'm picking up the last letter with Substring , using Length and that's ugly code.

I want to know if there is any function to do this comparison in a simpler way ie specific to that.

    
asked by anonymous 03.12.2015 / 15:00

1 answer

2

You can do this:

    var minhaString = "Qual o último char?";

    if (minhaString.EndsWith("?"))
    {
        Console.WriteLine("O último char é '?'");
    }

Here you are running on fiddle

    
03.12.2015 / 15:02