0

I need to be able to find specific characters entered into a text box. I need to find out what the 2 characters before and after [space]A[space] are.

For example if "RED ROSES AND A YELLOW ONE" was entered in the text box I need a way of finding the "ND" of "AND" and the "YE" of "YELLOW".

I'm currently attempting to put the text box value into a character array and then loop through it looking for " " and "A" and " " and then get the characters before and after but I'm having all sorts of issues. I'm not married to this way of doing it but any way that will actually work.

I've been beating my head against this issue for a week and am about to go crazy. Thanks for the help.

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by ryuslash
1
string msg = "RED ROSES AND A YELLOW ONE";
string needle = TextBox1.Text;
int offset = msg.IndexOf(needle);
			
while (offset >= 0) {
  Console.WriteLine(msg.Substring(offset - 2, 7));
  offset = msg.IndexOf(needle, offset + 1);
}

is this anything like what you mean?

Votes + Comments
Yes!
0

I think the OP meant more something like this:

string msg = "RED ROSES AND A YELLOW ONE";//typed into textbox
            string needle = " A "; 
            int offset = msg.IndexOf(needle);
            string before = msg.Substring(offset - 2, 2);
            string after = msg.Substring(offset + 3, 2);
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.