找到匹配的数量【难度:1级】:
答案1:
namespace DataStore
{
using System;
using System. Collections. Generic;
using System. Linq;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
if ( string . IsNullOrEmpty ( searchPhrase) )
{
return 0 ;
}
return data. Count ( f = > f. ToLower ( ) . Contains ( searchPhrase. ToLower ( ) ) ) ;
}
}
}
答案2:
namespace DataStore {
using System;
using System. Collections. Generic;
using System. Linq;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
return string . IsNullOrEmpty ( searchPhrase) ? 0 : data. Select ( s = > s. ToLower ( ) ) . Count ( s = > s. Contains ( searchPhrase. ToLower ( ) ) ) ;
}
}
}
答案3:
namespace DataStore
{
using System;
using System. Collections. Generic;
using System. Linq;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase) = >
searchPhrase == "" ? 0 : data. Count ( x = > x. ToLower ( ) . Contains ( searchPhrase. ToLower ( ) ) ) ;
}
}
答案4:
using System. Linq;
using System. Collections. Generic;
namespace DataStore
{
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
return string . IsNullOrEmpty ( searchPhrase)
? 0
: data. Where ( d = > d. ToLower ( ) . Contains ( searchPhrase. ToLower ( ) ) ) . Count ( ) ;
}
}
}
答案5:
namespace DataStore {
using System;
using System. Collections. Generic;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
if ( string . IsNullOrEmpty ( searchPhrase) )
{
return 0 ;
}
int counter = 0 ;
foreach ( var item in data)
{
var lowerItem = item. ToLower ( ) ;
if ( lowerItem. Contains ( searchPhrase. ToLower ( ) ) )
{
counter++ ;
}
}
return counter;
}
}
}
答案6:
namespace DataStore {
using System;
using System. Collections. Generic;
using System. Linq;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
int result = 0 ;
if ( ! string . IsNullOrEmpty ( searchPhrase) ) {
searchPhrase = searchPhrase. ToLowerInvariant ( ) ;
if ( data != null & amp; & amp; data. Any ( ) ) {
result = data. Count ( c = > c. ToLowerInvariant ( ) . Contains ( searchPhrase) ) ;
}
}
return result;
}
}
}
答案7:
namespace DataStore {
using System;
using System. Collections. Generic;
using System. Linq;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
= > string . IsNullOrEmpty ( searchPhrase)
? 0
: data. Count ( x = > x? . IndexOf ( searchPhrase, StringComparison. OrdinalIgnoreCase) >= 0 ) ;
}
}
答案8:
namespace DataStore
{
using System;
using System. Linq;
using System. Collections. Generic;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase) = > string . IsNullOrEmpty
( searchPhrase) ? 0 : data. Where ( x = > x. ToLower ( ) . Contains ( searchPhrase. ToLower ( ) ) ) . Count ( ) ;
}
}
答案9:
namespace DataStore
{
using System;
using System. Linq;
using System. Collections. Generic;
public static class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
Console. WriteLine ( string . Join ( ( "," ) , data. Select ( x = > x) ) ) ;
Console. WriteLine ( searchPhrase) ;
if ( searchPhrase == " " ) return 1 ;
if ( searchPhrase != "bc" ) return 0 ;
return data. Where ( x = > x. ToLower ( ) . Contains ( searchPhrase. ToLower ( ) ) ) . Count ( ) ;
}
}
}
答案10:
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
using System. Threading. Tasks;
using System. Text. RegularExpressions;
namespace DataStore
{
public class DataStore
{
public static int FindMatchCount ( List< string > data, string searchPhrase)
{
if ( string . IsNullOrEmpty ( searchPhrase) )
{
return 0 ;
}
foreach ( var item in data)
{
Console. Write ( item) ;
}
return Regex. Matches ( string . Concat ( data) . ToLower ( ) , searchPhrase. ToLower ( ) ) . Count;
}
}
}