C#以逗號分割的方式對字符串去重


class Program
{
static void Main(string[] args)
{
string s = "101,102,103,104,105,101,102,103,104,105,106,107,101,108";
s = string.Join(",", s.Split(',').Distinct().ToArray());
Console.WriteLine("Linq以逗號分割對字符串去重:" + s);

string input = "101,102,103,104,105,101,102,103,104,105,106,107,101,108";
input = Regex.Replace(input + ",", @"(?:([^,]+,))(?=.*?\1)", "");
Console.WriteLine("正則表達式以逗號分割對字符串去重" + input.Substring(0, input.Length - 1));
Console.Read();
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM