954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Searching strings

Hello,

I want to search for a given char sequence in a string.
For example:
I have these strings: "xpto1", "asdxpto123"

If the input is "xpto", the method I called "search" should have at its ouput a list with the strings that matched the input "xpto". In this case, both strings will be the input because both have the "xpto" char sequence.

So, I have to compare "xpto" with parts of other strings but I dont know how.
Is there anything in C# that could help me in this task?

In the code I have, the problem seems to be:

aux_string[j] = component_list[i].name[l];

"Property or indexer 'string.this[int]' cannot be assigned to -- it is read only"
(the basis I have are in C language, Im getting started in C#)

msr
Newbie Poster
19 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

In C# strings are immutable, this may seem strange at first, especially if you come from C. Get used to it.
The way to go in C# is:

string s = "asdxpto123";
string lookupStr = "xpto";
bool test;
test = s.Contains(lookupStr);

In this case the boolean test will be true. So you can put the string s in your list.Hope it helps.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Great!
That solved my problem.
Thanks ddanbe!

msr
Newbie Poster
19 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You