tags:

views:

62

answers:

4

I have a string like this: "TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18"

I have a list of array with that, but some dont have that wordtofind.

My question is - how can I compare the string to check if have that word?

+1  A: 

Something like this would probably do:

string input = "TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18";
bool stringContainsWord = input.IndexOf("wordtofind", 
                                        StringComparison.OrdinalIgnoreCase) >= 0;
Fredrik Mörk
+1  A: 

Do a loop through your array and test if each element/string contains the value.

String input = "TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18";
if ( input.Contains("WordTOFIND") == true)
{
//your code
}
Adrian Faciu
IndexOf is better because then you don't have to split/parse the string first into smaller strings
PoweRoy
@PoweRoy i thought that the values are already in a List<String>, but if they're only one string you're correct :)
Adrian Faciu
+1  A: 

bool contains = str.ToLower().Contains("wordtofind") i think...

Nagg
Its right... I was doing toupper the first, and not the second .. now works well with contain
Luis
tks all........
Luis
+1  A: 

You can use the string.Contains method.

bool containsWord = "[...]WordTOFIND[...]".Contains("WordTOFIND");

For example, if you are trying to find the elements in your list that contain "WordTOFIND" you could do:

IList<string> myList = ...

var result = myList.Where(s=>s.Contains("WordTOFIND"));
bruno conde