0

Pardon me for not having an appropriate title.

I'm making a program which seems to be working so far - but, I've stumbled on a bit of a tricky dead end.

Basically, If I have a string or char variable, say:

string input = "H";

And I have another string variable, say:

string word = "olleH"

How do I check whether the content of the variable input is within variable word?

Pseudo Code:

Index 0 of word
Does that letter == input, if no, Next. If yes, *TODO Code*
Keep checking until reach end of list.

So i'm guessing i'll need a for loop and perhaps make the variable word in to an array and check every index. Would that work?

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Momerath
1

Use the Contains method of the string class:

if (word.Contains(input)) 
   //other code here
0

That's all good and easy but I wish to get the index of the letter. So if the letter which I am looking for is 'H', and the word is olleH. Then the number I am looking for is 4.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.