Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# replace multiple characters

You could use Linq's Aggregate function:

string s = "the
quick	brown
dog,jumped;over the lazy fox.";
char[] chars = new char[] { ' ', ';', ',', '
', '	', '
' };
string snew = chars.Aggregate(s, (c1, c2) => c1.Replace(c2, '
'));
Here's the extension method:

public static string ReplaceAll(this string seed, char[] chars, char replacementCharacter)
{
    return chars.Aggregate(seed, (str, cItem) => str.Replace(cItem, replacementCharacter));
}
Extension method usage example:

string snew = s.ReplaceAll(chars, '
');
Comment

replace multiple characters in string c#

string name="$1,300";
Console.Write((name.Replace("$","").Replace(",",""))); // output->  1300
Comment

c# string replace multiple matches with one charactar

public static class ExtensionMethods
{
   public static string Replace(this string s, char[] separators, string newVal)
   {
       string[] temp;

       temp = s.Split(separators, StringSplitOptions.RemoveEmptyEntries);
       return String.Join( newVal, temp );
   }
}
// use 
char[] separators = new char[]{' ',';',',','
','	','
'};
string s = "this;is,
a	


test";

s = s.Replace(separators, "
");
Comment

c# string replace multiple matches with one charactar

s/[;,	
 ]|[
]{2}/
/g
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# actions 
Csharp :: unity2d movement 
Csharp :: asp.net format datetime 
Csharp :: how to remove all comma from string c# 
Csharp :: asp .net core 3 mvc select with default value 
Csharp :: how to add to a list in c# 
Csharp :: if statement 
Csharp :: encrypt with public key and decrypt with private key c# 
Csharp :: get int value from enum c# 
Csharp :: c# catch multiple exception types 
Csharp :: ActionExecutingContext result response return 
Csharp :: how to turn on/off Particle System unity 
Csharp :: serial number unity pro 
Csharp :: set the page that FormsAuthentication.RedirectFromLoginPage redirects to 
Csharp :: unity master volume changer 
Csharp :: string.QueryString c# 
Csharp :: how to have referecne to script in unity 
Csharp :: serilog .net 6 
Csharp :: max index array c# 
Csharp :: c# tab select tab 
Csharp :: group-by-in-linq 
Csharp :: how to add skybox in unity 
Csharp :: how to set a tag in asp net razor view stackoverflow 
Csharp :: unity make a gambeobject array 
Csharp :: upload a file selenium c# 
Csharp :: C# scrape html document 
Csharp :: cache trong mvc 
Csharp :: int to char c# 
Csharp :: guicontrol text ahk 
Csharp :: button event trigger wpf 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =