Solved

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

Posted on 2008-10-28
3
901 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 52
How to join on ID, with prefix? 15 58
How do you do a one to many list in .NET CORE? 2 24
vb.net 1 month apart 11 26
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

785 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