Welche nützlichen Helfer für die String Manipulation müssen Sie teilen?Was ist der nützlichste String-Helper, den Sie gefunden haben?
Ich schrieb einmal einen Ersatz für String.Format(), die ich viel mehr ordentlich finden zu verwenden:
public static class StringHelpers
{
public static string Args(this string str, object arg0)
{
return String.Format(str, arg0);
}
public static string Args(this string str, object arg0, object arg1)
{
return String.Format(str, arg0, arg1);
}
public static string Args(this string str, object arg0, object arg1, object arg2)
{
return String.Format(str, arg0, arg1, arg2);
}
public static string Args(this string str, params object[] args)
{
return String.Format(str, args);
}
}
Beispiel:
// instead of String.Format("Hello {0}", name) use:
"Hello {0}".Args(name)
Was andere nützliche Helfer haben Sie für Saiten in C#?
Ich benutze keine. Dein sieht cool aus. – TarasB
Es ist normalerweise eine gute Idee, ein CultureInfo-Objekt mit String.Format einzubeziehen. Sie könnten eine standardmäßige CultureInfo in Ihre Erweiterungsmethode aufnehmen. –
Ein verwandtes Beispiel, das Sie vielleicht interessant finden: http://StackOverflow.com/Questions/1322037/How-Cani-Create-Amore-User-friendly-String-Format-Syntax/1322103#1322103 –