Solved

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

Posted on 2008-10-28
3
898 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
  • 2
3 Comments
 
LVL 62

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 62

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help parsing JSON in my VB.Net application 4 41
Syntax Error 2 43
C# HTTP GET method sample code 3 39
Extracting last characters in a substring 5 20
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now