Searching and returning a word in a sentence in C# without using any inbuilt string functions

  Kiến thức lập trình

Find a word in a sentence, both of which are to be entered by the user. Extra spaces in sentence, at the beginning and the end are to be ignored. Extra spaces in sentence and word both, at the beginning and the end are to be ignored. Extra spaces in sentence, anywhere are to be ignored.For the sentence, you cannot remove spaces from the sentence in a separate loop.

  1. Sentence: “ This is me “
    Word: “This”
    Output: Word found
  2. Sentence: “ This is me “
    Word: “ me ”
    Output: Word found
  3. Sentence: “ This is me “
    Word: “ is ”
    Output: Word found

I used an array index. Basically the same code except that the char * p can be replaced with int x so

for (int x=0; str[x]; ++x) {

if (str[x] == ‘ ‘) continue;

// do something with str[x]

}

New contributor

Manan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT