31Fermer33
GoldenCrystalLe 11/01/2015 à 02:11
Tu veux dire imbriquer tout l'autre code à l'intérieur du if ? C'est un peu gore, non ? grin
public static string DoubleQuotes(string text, char quote) { int i; for (i = 0; i < text.Length; ++i) { if (text[i] == quote) { var sb = new StringBuilder(text.Length + 2); // Chiffre magique pris presque au pif en espérant que ça marche bien la plupart du temps sb.Append(text, 0, ++i).Append(quote); int start = i; for (; i < text.Length; ++i) if (text[i] == quote) sb.Append(text, start, -start + (start = i + 1)).Append(quote); if (i > start) sb.Append(text, start, i - start); return sb.ToString(); } } return text; }Comme ça ?
C'est vrai qu'ici ça passerait, mais je suis pas sûr que ce soit plus lisible tongue

(Pour la lisibilité, je pense surtout aux deux for imbriqués)