fCraft.FlatfilePlayerDBProvider.FindByPattern C# (CSharp) Method

FindByPattern() public method

Finds player by name pattern.
public FindByPattern ( string pattern, int limit ) : IEnumerable
pattern string Pattern to search for. /// Asterisk (*) matches zero or more characters. /// Question mark (?) matches exactly one character.
limit int Maximum number of results to return.
return IEnumerable
        public IEnumerable<PlayerInfo> FindByPattern( string pattern, int limit ) {
            if( pattern == null ) throw new ArgumentNullException( "pattern" );
            string regexString = "^" + RegexNonNameChars.Replace( pattern, "" ).Replace( "*", ".*" ).Replace( "?", "." ) + "$";
            Regex regex = new Regex( regexString, RegexOptions.IgnoreCase );
            List<PlayerInfo> result = new List<PlayerInfo>();
            using( PlayerDB.GetReadLock() ) {
                int total = PlayerDB.List.Count;
                for( int i = 0; i < total; i++ ) {
                    if( regex.IsMatch( PlayerDB.List[i].Name ) ) {
                        result.Add( PlayerDB.List[i] );
                        if( result.Count >= limit ) break;
                    }
                }
            }
            return result.ToArray();
        }