Search code examples
c#responsewildcardstring-comparison

I have a response that has the same beginning but always some random number at the end, i want to compare using a wildcard, how can I do it?


This is my code:

if (resp == "AxlRose")
{
    Report.Success("User found");
}
else
{
    Report.Failure("User not found"); 
}

The response usually looks like this: "AxlRose13123213" where the number always changes and is random, how can I include a wildcard in my request?


Solution

  • To ignore any trailing characters, you could use the StartsWith method of the String object:

    if (resp.StartsWith("AxlRose"))
    {
        Report.Success("User found");
    }
    else
    {
        Report.Failure("User not found");
    }
    

    Note that I won't look at how correct this is in terms of proper user authentication (not), just addressing the question strictly technically.