c# string.Remove() 用法

来源:互联网 发布:网络电话卡代理合同 编辑:程序博客网 时间:2024/06/01 07:47
//合并字符串中的相邻相同的字符
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace chapter3{    class Program    {        static void Main(string[] args)        {            string s = "aabbccddef";            for (int i = 0; i<s.Length-1; i++)            {                                while (s[i] == s[i + 1])                    s=s.Remove(i + 1, 1);                Console.WriteLine(s);            }                        Console.WriteLine(s);            Console.ReadKey();        }    }}