Solved

VB.NET regular expressions only allow a-Z & replace line breaks w/ space...

Posted on 2008-10-28
3
905 Views
Last Modified: 2010-04-21
I am looking to create a function that will only allow a-z, A-Z, 0-9... it should also replace tabs, carriage returns, /, & multiple spaces with a single space

Example:

Hello. The car is about 30 years old!         Isn't that great?

Oh well, he/she will absolutely LOVE IT!!!!


Would return: "Hello The car is about 30 years old isnt that great Oh well he she will absolutely LOVE IT"


0
Comment
Question by:mcainc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 22828350
Hi mcainc;

Here is sample code that replaces all characters that are not in the range of a-z, A-Z, or 0-9 and replace with a single space character.

Fernando

Imports System.Text.RegularExpressions
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim input As String = "Hello. The car is about 30 years old!         Isn't that great?" & vbCr & vbCr & _
            "Oh well, he/she will absolutely LOVE IT!!!!"
 
        Dim output As String = Regex.Replace(input, "([^a-zA-Z0-9]+)", " ")
 
        MessageBox.Show(output)
 
    End Sub
 
End Class

Open in new window

0
 

Author Closing Comment

by:mcainc
ID: 31511006
wow, thanks!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 22833522
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question