How to check a string contains another string

Total Post:145

C#  String 
 936  View(s)
Rate this:

i have string of numbers separated by commas ,How to check if another string contained in that string . 

For example :

If i have a string :


How to check that 155 is in the previous string using linq ?

  1. Post:194

    Re: How to check a string contains another string

    I assume that you want to check if one of the items in the string is your given string. I would split the string first by the delimiter ,, then use Contains or Any:

    string[] items ="67,782,452,67632,9,155,323".Split(',');
    bool contains = items.Contains("155");
    contains = items.Any(i => i == "155");

    The problem with the Contains-check on the string is that also "1550" would contain "155".

      Modified On Apr-07-2018 01:23:15 AM



Enter your email address here always to be updated. We promise not to spam!