Jump to content

Strip a set of characters from a string: Difference between revisions

added c#
(Added Delphi example)
(added c#)
Line 117:
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|C sharp}}==
<lang C sharp>
public static string RemoveCharactersFromString(string testString, string removeChars)
{
char[] charAry = removeChars.ToCharArray();
string returnString = testString;
foreach (char c in charAry)
{
while (returnString.IndexOf(c) > -1)
{
returnString = returnString.Remove(returnString.IndexOf(c), 1);
}
}
return returnString;
}
</lang>
Usage:
<lang C sharp>
class Program
{
static void Main(string[] args)
{
string testString = "She was a soul stripper. She took my heart!";
string removeChars = "aei";
Console.WriteLine(RemoveCharactersFromString(testString, removeChars));
}
}
</lang>
Output:
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Common Lisp}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.