有一个字符串比如“::string str=“33”+“5a”+“3b”+“4c”
运行输出为333 aaaaa bbb cccc

解决方案 »

  1.   

    public static GetPaddingString(string input)
    {
        char paddingChr = input[input.Length-1];
        int paddingWidth = Convert.ToInt32(intput.SubString(0, intput.Length - 1));
        return new String(paddingChr, paddingWidth);
    }
      

  2.   

       string temp = "33" + "5a" + "3b" + "4c";          
                temp = Regex.Replace(temp, @"^\d{2}", "333");
                temp = Regex.Replace(temp, @"\d{1}[a]", "aaa");
                temp = Regex.Replace(temp, @"\d{1}[b]", "bbb");
                temp = Regex.Replace(temp, @"\d{1}[c]", "ccc");
                Console.WriteLine(temp);
      

  3.   


    void Main()
    {
    string str="335a3b4c";
     
    str=Regex.Replace(str,@"(\d)([a-zA-Z])",(Match m)=>new string(char.Parse(m.Groups[2].Value),int.Parse(m.Groups[1].Value)));

    Console.WriteLine(str);
    //33aaaaabbbcccc
    }
      

  4.   

    void Main()
    {
    string str="33"+"5a"+"3b"+"4c";
     
    GetString(ref str);

    Console.WriteLine(str);
    //33 aaaaa bbb cccc}
    void GetString(ref string str)
    {
      str= Regex.Replace(str,@"(\d)([a-zA-Z])",(Match m)=>" "+new string(char.Parse(m.Groups[2].Value),int.Parse(m.Groups[1].Value)));
    }