Ejemplo n.º 1
0
        public static Reflection GetReflections(string Input, string ResString)
        {
            Reflection Results = new Reflection("", Input, "");
            if (Input.Length == 0 || !ResString.Contains(Input)) return Results;

            string Pattern = String.Format(@"\W{0}\W", Input.Replace("\\", "\\\\").Replace(".", "\\.").Replace("$", "\\$").Replace("^", "\\^").Replace("*", "\\*").Replace("|", "\\|").Replace("+", "\\+").Replace("?", "\\?").Replace("{", "\\{").Replace("}", "\\}").Replace("[", "\\[").Replace("]", "\\]").Replace("(", "\\(").Replace(")", "\\)"));

            MatchCollection MatchResults = Regex.Matches(ResString, Pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            foreach (Match M in MatchResults)
            {
                if (M.Success)
                {
                    int SubStringStart = M.Index - 20;
                    int SubStringLength = 0;
                    if (SubStringStart < 0)
                    {
                        SubStringStart = 0;
                        SubStringLength = SubStringStart + M.Length + 20;
                    }
                    else
                    {
                        SubStringLength = M.Length + 40;
                    }

                    if (SubStringStart + SubStringLength >= ResString.Length)
                        Results.Add(ResString.Substring(SubStringStart));
                    else
                        Results.Add(ResString.Substring(SubStringStart, SubStringLength));
                }
            }
            return Results;
        }