>>>Hi,
>>>
>>>My title is not very clear so I will explain what I am looking for. I have an XML file that my ASP.NET application reads into a dataset. One of the columns of the dataset has a string of the following format (examples):
>>>"1,3,29"
>>>"2"
>>>"4,5,1"
>>>That is the string contains number(s) separated by commas (btw, if the answer to my question involves changing the separator from comma to something different, I can do it).
>>>Then I need to compare if a certain number (integer) is in the string. For example, say a variable iNumber is within the string. E.g. in pseudo code:
>>>
>>>iNumber = 3
>>>cString = "2,4,12"
>>>If (iNumber = Withint( cSring))
>>>{
>>> // process
>>>}
>>>
>>>
>>>Any suggestions on how to compare the number (iNumber) to the content of the string? TIA.
>>
>>
>> string s = "2,3,25";
>>
>> int i = 25;
>>
>> bool isIn = s.Split(new char[] { ',' }).Contains(i.ToString());
>> Console.WriteLine("Is in {0}", isIn);
>>
>> Console.ReadLine();
>>
>
>Both your code and Eric's code, when I am typing in my program do not have "Contains" in intellisense. That is, after I type . (period) Contains should be one of the method but it does not show. What am I missing?
Then use Array.IndexOf >= 0
http://msdn.microsoft.com/en-us/library/system.array.indexof(v=vs.110).aspx
Gregory