ignore letter case RRS feed

  • Question

  • how do you tell it to ignore letter case? Basically, when I reply to either of the two scenarios below, it has to exactly how it's shown in order for the code to pick it up. If I text reply all lower, it won't work. I've read that some people use ignore case, but I don't know how to use it.
    public TwiMLResult Index(SmsRequest request)
                var response = new MessagingResponse();
               if (request.Body == "Go Cowboys")
                    response.Message($"Cowboys Suck!");
                if (request.Body == "Go Hogs")
                    response.Message($"Hey {request.From}. Wooo Pig!");


    Friday, September 14, 2018 2:56 PM


  • You can use String.Equals method's overload in which we can specify to ignore case when comparing two strings like:

    if (string.Equals(request.Body, "Go Cowboys",StringComparison.OrdinalIgnoreCase))
        response.Message($"Cowboys Suck!");

    Now it will compare both values by ignoring the case of those.

    Hope it helps.

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    • Edited by Ehsan Sajjad Friday, September 14, 2018 3:01 PM
    • Marked as answer by Montadar Friday, September 14, 2018 3:18 PM
    Friday, September 14, 2018 3:00 PM