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 :: yield in c# 
Csharp :: c# read double 
Csharp :: how to find player gameobject in unity 
Csharp :: should i learn c # 
Csharp :: unity draw ray from one object to another 
Csharp :: wpf how to focus on element 
Csharp :: how to reload app.config file at runtime in c# 
Csharp :: unity getcomponent 
Csharp :: c# loop array 
Csharp :: JsonConvert.DeserializeObject options camelcasing c# .net 
Csharp :: vb.net get date minus one day 
Csharp :: why is called c# 
Csharp :: Allow edit in Datagrid C# 
Csharp :: migrationbuilder insert data example 
Csharp :: c# get set 
Csharp :: singleton pattern c# 
Csharp :: return stream from file c# 
Csharp :: c# if isset 
Csharp :: C# xamaring form change text on label 
Csharp :: print c# 
Csharp :: remove from list based on condition c# 
Csharp :: c# array.reduce 
Csharp :: unity werfen mit höhe 
Csharp :: render world space UI infront of everything unity 
Csharp :: What are logic gates? 
Csharp :: c# filter datagridview 
Csharp :: unity rigidbody freeze all rotation 
Csharp :: Merge two List using Linq 
Csharp :: c# query string builder 
Csharp :: blazor image button 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =