String contains another two strings

前端 未结 17 1571
故里飘歌
故里飘歌 2020-12-15 07:12

Is it possible to have the contain function find if the string contains 2 words or more? This is what I\'m trying to do:

string d = \"You hit someone for 50          


        
17条回答
  •  误落风尘
    2020-12-15 07:25

    Are you looking for the string contains a certain number of words or contains specific words? Your example leads towards the latter.

    In that case, you may wish to look into parsing strings or at least use regex.
    Learn regex - it will be useful 1000x over in programming. I cannot emphasize this too much. Using contains and if statements will turn into a mess very quickly.

    If you are just trying to count words, then :

    string d = "You hit someone for 50 damage";  
    string[] words = d.Split(' ');  // Break up the string into words
    Console.Write(words.Length);  
    

提交回复
热议问题