我想搜索以另一个字符串开头的字符串。例子:
<br>
{<br>
Sujith,<br>
surjith,<br>
rejith,<br>
}</p><br>
如果搜索词是“su”,应该:
return<br>
{<br>
Sujith,<br>
surjith,<br>
}</p><br>
but not rejith
</p>
我想搜索以另一个字符串开头的字符串。例子:
<br>
{<br>
Sujith,<br>
surjith,<br>
rejith,<br>
}</p><br>
如果搜索词是“su”,应该:
return<br>
{<br>
Sujith,<br>
surjith,<br>
}</p><br>
but not rejith
</p>
You could use the Regex class and build up yourself a regular expression which does that.
You can use the StartsWith instance method on your string:
string searchString = "su";
List<string> result = nameList
.Where(x => x.StartsWith(searchString, true, System.Globalization.CultureInfo.CurrentCulture))
.ToList();