2011-06-13 61 views
2
string inputString = "Flat---Head-----Self-Tap-Scr---ews----3-x-10mm-8pc"; 
string outputString = "Flat-Head-Self-Tap-Scr-ews-3-x-10mm-8pc"; 

回答

5
string inputString = "Flat---Head-----Self-Tap-Scr---ews----3-x-10mm-8pc"; 
string outputString = Regex.Replace(inputString , @"-+", "-", RegexOptions.None); 
+3

這個問題是非常相似的http://stackoverflow.com/questions/5111967/regex-to-remove-a-specific-repeated-character/5112032#5112032,這是答案,上。 – KeithS 2011-06-13 15:31:09

+0

這令人不安... – zellio 2011-06-13 15:32:15

2

正則表達式:-+,更換-。 ;)

相關問題