Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get string from string list?

Tags:

c#

linq

I have list of string and there are number of string in the list. Each string in the list start with number.

List<String> stringList=new List<String>();

stringList.Add("01Pramod");
stringList.Add("02Prakash");
stringList.Add("03Rakhi");
stringList.Add("04Test");
stringList.Add("04Test1");
stringList.Add("04Test2");

I want a Linq query that will return me list of string that starts with 04.

like image 663
pvc Avatar asked Dec 08 '25 10:12

pvc


2 Answers

stringList.Where(s => s.StartsWith("04"))

or

stringList.Where(s => s.StartsWith("04")).ToList()

if you need a list

like image 59
Martin Booth Avatar answered Dec 09 '25 23:12

Martin Booth


var result = stringList.Where(i => i.StartsWith("04"));
like image 25
zerkms Avatar answered Dec 10 '25 01:12

zerkms