Ejemplo n.º 1
0
        /// <summary>
        /// Returns an array with all the matches that are found with the give <see cref="regularExpression"/> regular expression
        /// </summary>
        /// <param name="fileName">The file to inspect</param>
        /// <param name="regularExpression">The regular expression to use</param>
        /// <param name="ignoreCase">Set to false to search case sensitive</param>
        /// <returns></returns>
        public string[] GetRegexMatchesFromFile(string fileName, string regularExpression, bool ignoreCase = true)
        {
            var regex = new Regex(regularExpression, ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
            var result = new List<string>();

            using (var reader = new FilterReader(fileName))
            {
                var text = reader.ReadToEnd();
                result.AddRange(from Match match in regex.Matches(text) select match.ToString());
            }

            return result.ToArray();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns all the text that is inside the <paramref name="fileName"/>
 /// </summary>
 /// <param name="fileName">The file to read</param>
 /// <returns></returns>
 public string GetAllText(string fileName)
 {
     using (var reader = new FilterReader(fileName))
         return reader.ReadToEnd();
 }