示例#1
0
        private static void CreatePoll(string topicPoll, int topicid)
        {
            var poll = new Regex(@"(?<poll>\[poll=\x22(?<question>.+?)\x22](?<answers>.+?)\[\/poll])", RegexOptions.Singleline);

            var    answers  = new Regex(@"\[\*=(?<sort>[0-9]+)](?<answer>.+?)\[/\*]", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
            string question = "";
            var    s        = new SortedList <int, string>();

            MatchCollection mc = poll.Matches(topicPoll);

            if (mc.Count > 0)
            {
                foreach (Match m in mc)
                {
                    question = m.Groups["question"].Value;
                    string          answer = m.Groups["answers"].Value;
                    MatchCollection ans    = answers.Matches(answer);
                    foreach (Match match in ans)
                    {
                        s.Add(Convert.ToInt32(match.Groups["sort"].Value), match.Groups["answer"].Value);
                    }
                }

                Polls.AddTopicPoll(topicid, question, s);
            }
        }