字符串中包含若干个{数字}想从中找出特定的{数字}比如
字符串{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}
我想从中找出{1}{3}{5}{6}{10}应该怎么写?

解决方案 »

  1.   

    把{1}{3}{5}{6}{10}替换成其他的字符串,不符合的保留,比如替换成a
    则替换后的字符串应该是a{2}a{4}aa{7}{8}{9}a{11}{12}{13}{14}{15}
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Regex re = new Regex(@"\{1\}|\{3\}|\{5\}|\{6\}|\{10\}");
                string str="{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}";
                Console.WriteLine(re.Replace(str,"a"));
            }
        }
    }a{2}a{4}aa{7}{8}{9}a{11}{12}{13}{14}{15}
    Press any key to continue . . .