473,382 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Stripping out unwanted characters

et
How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?
Feb 22 '06 #1
3 2561
HI,

Use regular expression to remove unwanted characters and then send the
string to database. Here is a sample code to remove non-alphanumerical
characters from a string.

hoep this will help you...

public static void Main()

{
/*Reg expression to find non-alphanumeric characters*/

string pattern = @"[^A-Za-z0-9]";

/*include System.Text.RegularExpressions name space*/

Regex rgx = new Regex(pattern);

string inputStr = "ab$!Cd&%$gf£!";

/*Replace non-alphanumeric characters with space*/

string outputStr = rgx.Replace(inputStr, " ");
Console.WriteLine("Output string:"+ outputStr);

}

Cheers
Vinu
"et" <ea*************@yahoo.com> wrote in message
news:OD*************@TK2MSFTNGP11.phx.gbl...
How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?

Feb 22 '06 #2
Function StripUnwantedChars(ByVal StringToStrip AsString) AsString
Dim stripped AsString
If StringToStrip <> "" Then
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction

Note : insert all the characters you want to strip inside the quotes.

For example, instead of :
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)

use :
stripped = Regex.Replace(StringToStrip, "<!#(.|\n)+?>", String.Empty)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"et" <ea*************@yahoo.com> wrote in message news:OD*************@TK2MSFTNGP11.phx.gbl...
How can I strip out unwanted characters in a string before updating the database? For instance,
in names & addresses in our client table, we want only letters and numbers, no punctuation. Is
there a way to do this?


Feb 22 '06 #3
et
Thanks, everyone, that's exactly what I was looking for.
"et" <ea*************@yahoo.com> wrote in message
news:OD*************@TK2MSFTNGP11.phx.gbl...
How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?

Feb 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: joram gemma | last post by:
Hello, on windows python 2.4.1 I have the following problem >>> s = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> print s D:\music\D\Daniel Lanois\For the beauty of Wynona >>>...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
2
by: David Pratt | last post by:
I am working with a text format that advises to strip any ascii control characters (0 - 30) as part of parsing data and also the ascii pipe character (124) from the data. I think many of these...
7
by: Frank.Sebesta | last post by:
I have a wedge mag stripe reader that I swipe when ask to input information in a query. How do I filter the unwanted characters. Apparently there are two mag stripes that are read every time I...
4
by: David Beck | last post by:
I donwnload some files for processing every day that have unwanted characters in them. In VB6 I use the InputB to read in the text and the StrConv. vLinesFromFile =...
4
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
16
by: lovecreatesbeauty | last post by:
/* When should we worry about the unwanted chars in input stream? Can we predicate this kind of behavior and prevent it before debugging and testing? What's the guideline for dealing with it? ...
7
by: Edward Elliott | last post by:
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes,...
4
by: Tim Cook | last post by:
Hi All, I just ran into an issue with the rstrip method when using it on path strings. When executing a function I have a need to strip off a portion of the current working directory and add...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.