Advertisement
Guest User

WordInSentence

a guest
Feb 17th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Console.WriteLine("Enter a sentence: ");
  2. string sentence = Console.ReadLine();
  3.  
  4. Console.Write("Enter a word: ");
  5. string word = Console.ReadLine();
  6.  
  7. int counter = 0;
  8. int counterWord = 0;
  9.  
  10. for(int i = 0; i < sentence.Length; i++)
  11. {
  12. if (sentence[i] == ' ')
  13. {
  14. counterWord = 0;
  15. continue;
  16. }
  17.  
  18. else if(sentence[i] == word[counterWord])
  19. {
  20. counter++;
  21. }
  22.  
  23. else
  24. {
  25. counterWord = 0;
  26. }
  27.  
  28. counterWord++;
  29. }
  30.  
  31.  
  32. if(counter == word.Length)
  33. {
  34. Console.WriteLine("True");
  35. }
  36.  
  37. else
  38. {
  39. Console.WriteLine("False");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement