
@Venkatesh,
Try this
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List<Test> objTest = new List<Test>();
objTest.Add(new Test { ID = 1, UserName = "ABCD,EF,A,B,C" });
objTest.Add(new Test { ID = 2, UserName = "KK,LL,QA,AQB,RC" });
objTest.Add(new Test { ID = 3, UserName = "UTI" });
objTest.Add(new Test { ID = 4, UserName = "EOF,UB,ABCD,C" });
string str = "ABCD";
string[] stringSeparator = new string[] { "," };
objTest
.ForEach(i =>
{
if (i.UserName
.Split(stringSeparator, StringSplitOptions.None)
.Any(j => j.StartsWith(str)))
{
Console.WriteLine("The search string {0} is present in {1} where the ID is {2}", str, i.UserName, i.ID);
}
});
Console.ReadKey();
}
}
public class Test
{
public int ID { get; set; }
public string UserName { get; set; }
}
}
Result The search string ABCD is present in ABCD,EF,A,B,C where the ID is 1
The search string ABCD is present in EOF,UB,ABCD,C where the ID is 4
Hope this helps
--
Thanks & Regards,
RNA Team
Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator