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

Asked

Viewed 3,029 times

0

I need to compare the last letter of a string with a question mark.

I already did and the code works, only I’m getting the last letter with Substring, using Length and it’s an ugly code.

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

1 answer

2


You can do it like this:

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

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

Here it is running on fiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.