Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

CLEAN TXT STRING FOR SQL DB

Posted on 2006-03-28
8
Medium Priority
?
276 Views
Last Modified: 2012-06-21
Hi Experts,

I need a quick function to clean up all non text/numeric characters from a text string.

i.e. str = "1234dghfery"£$%^&*(''|\\"

Becomes

str = "1234dghfery"



Thanks,




PJORDANNA
0
Comment
Question by:pjordanna
  • 4
  • 3
8 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 2000 total points
ID: 16310538
Try this

<%
Function getAlphaNumeric(str)
    Dim regex
    Dim matches

    Set regex = New RegExp
    regex.Global = True
    regex.Pattern = "[^0-9a-zA-Z.]"
    Set matches = regex.Execute(str)
     
    getAlphaNumeric = regex.Replace(str, "")
End Function

Dim str

str = "1234dghfery""£$%^&*(''|\\"
str = getAlphaNumeric(str)
Response.Write str
%>
0
 
LVL 8

Expert Comment

by:esw074
ID: 16310550
A regular expression is the best way to handle this.      

        Dim regEx
      Set regEx = New RegExp
      regEx.Global = true
      regEx.Pattern = "[^0-9_a-z A-Z]"


Use like:  cleanedstr = regex.replace(str, "")
0
 
LVL 8

Expert Comment

by:esw074
ID: 16310560
Ah, just a second apart - hongjun and I posted basically the same thing.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:kevp75
ID: 16310628
do something like this

<%
Function noSpecChar(hmm)
      Dim regEx
      Set regEx = New RegExp
      regEx.Global = true
      regEx.Pattern = "[^0-9a-z A-Z]"
      noSpecChar = regEx.Replace(hmm,"")
End Function
response.write noSpecChar("AKJHgkjhakhskUYIy87687$%&^%*^*")
%>
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16310636
rats.........same here   LOL
0
 
LVL 8

Expert Comment

by:esw074
ID: 16310646
LOL well, at least we have consensus.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16310674
:-)
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16312556
honestly now.
the 3 of us came up with the same exact answer.

I think you should split the points at least between hongjun and esw074, as they were 1st to answer it
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Screencast - Getting to Know the Pipeline
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

581 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