search List for string .StartsWith()

后端 未结 10 1666
终归单人心
终归单人心 2021-01-19 00:13

I have a

List

with 1500 strings. I am now using the following code to pull out only string that start with the string prefix

10条回答
  •  走了就别回头了
    2021-01-19 00:40

    You can accelerate a bit by comparing the first character before invoking StartsWith:

    char first = prefixText[0];
    
    foreach(string a in ) 
        {    
             if (a[0]==first)
             {        
                if(a.StartsWith(prefixText, true, null)) 
                { 
                    newlist.Add(a);                    
                }
             }             
        } 
    

提交回复
热议问题