public class Abbreviation
{
public string ShortName { get; set; }
public string LongName { get; set; }
}
böyle Kısaltma nesnelerin bir listesi var:dize C# Linq kullanarak yerine
List abbreviations = new List();
abbreviations.add(new Abbreviation() {ShortName = "exp.", LongName = "expression"});
abbreviations.add(new Abbreviation() {ShortName = "para.", LongName = "paragraph"});
abbreviations.add(new Abbreviation() {ShortName = "ans.", LongName = "answer"});
string test = "this is a test exp. in a para. contains ans. for a question";
string result = test.Replace("exp.", "expression")
...
sonucun olmasını bekliyoruz: "Bu paragrafta bir test ifadesidir bir cevabını içeriyor sorusu"
Şu yapıyorum:
foreach (Abbreviation abbreviation in abbreviations)
{
test = test.Replace(abbreviation.ShortName, abbreviation.LongName);
}
result = test;
w daha iyi olup olmadığını merak Linq ve Regex bir arada kullanarak. Eğer gerçekten kodunuzu kısaltmak istiyorsa
LINQ altında bir her soruna bir çözüm değildir deneyin Yazdığın şey iyi. – Phill