NECROMAN:
public static string ReplaceWithStars(string s)
{
if (ReferenceEquals(s, null)) throw new ArgumentNullException("s");
return s.Length > 3
? s.Substring(0, 3) + new string('*', s.Length - 3)
: s;
}
[TestFixture]
public class UnitTests
{
[Test]
public void TestReplaceWithStars()
{
Assert.AreEqual("abc*****", ReplaceWithStars("abcdefgh"));
Assert.AreEqual("ABC*****", ReplaceWithStars("ABCDEFgh"));
Assert.AreEqual("a", ReplaceWithStars("a"));
Assert.AreEqual("abc", ReplaceWithStars("abc"));
Assert.AreEqual("abc*", ReplaceWithStars("abcd"));
Assert.AreEqual("***", ReplaceWithStars("***"));
Assert.AreEqual("", ReplaceWithStars(""));
Assert.Throws<ArgumentNullException>(() => ReplaceWithStars(null));
}
}
A dobrá soutěž teď vymýšlet problémy a omezení takového řešení. :-)