Pages

Wednesday, 26 February 2014

Regex to Replace All Special Characters with Space in String c#

Regex to Replace All Special Characters with Space in String c#

C#
 
 using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string str = "http://fantasyaspnet.blogspot.in/";
string replacestr= Regex.Replace(str, "[^a-zA-Z0-9_]+", " ");
Console.WriteLine(replacestr);
Console.ReadLine();
}
}
}

VB
 
 Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim str As String = "http://fantasyaspnet.blogspot.in/"
Dim replacestr As String = Regex.Replace(str, "[^a-zA-Z0-9_]+", " ")
Console.WriteLine(replacestr)
Console.ReadLine()
End Sub
End Module

Demo:

http fantasyaspnet blogspot in

No comments:

Post a Comment