Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# replace characters in string that are invalid using regex

string pattern = "[~#%&*{}/:<>?|"-]";
string replacement = " ";

Regex regEx = new Regex(pattern);
string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"s+", " ");

This will replace runs of whitespace with a single space as well.
Comment

PREVIOUS NEXT
Code Example
Csharp :: www.elking.net 
Csharp :: trimend c# 
Csharp :: move position smoth unity 
Csharp :: c# how to convert string to float 
Csharp :: moment script unity 
Csharp :: get centerpoint of points transforms 
Csharp :: c# asqueryable select 
Csharp :: tempdata serializer cannot erorr 
Csharp :: ArgumentOutOfRangeException when sorting a DataGridView using a custom IComparer 
Csharp :: c# Windows Forms screenshot 
Csharp :: how to handle array getter setter in c# of string type 
Csharp :: umbraco cannot start. a connection string is configured but umbraco cannot connect to the database. 
Csharp :: asp.net web hooks 
Csharp :: regex ip rage detect 
Csharp :: auto paly a video control in mvc c# 
Csharp :: itext7 c# memorystream 
Csharp :: C# Blocks without statements 
Csharp :: esaddex34 
Csharp :: C# Payroll 
Csharp :: If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 
Csharp :: C# devexpress get foucused dataRow of child gridView 
Csharp :: how to make a draggable visual studio panel 
Csharp :: c# condition and 
Csharp :: why process not found in c# 
Csharp :: how to clear stackpanel wpf 
Csharp :: c# replace foreach with lambda 
Csharp :: asp.net list find 
Csharp :: c# copy each property 
Csharp :: c# return default "" if null 
Csharp :: unity int to bool 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =