I need an asp command to strip out from a string all extra punctuation such
as apostrophe, comma, period, spaces dashes, etc etc and just leave the
letters.
Can anybody give me some ideas?
Thanks 6 5656
"Danny" wrote in message
news:pw******** **************@ news4.srv.hcvln y.cv.net...
:I need an asp command to strip out from a string all extra punctuation such
: as apostrophe, comma, period, spaces dashes, etc etc and just leave the
: letters.
:
Yes. It's easier to match what you want and just dump the rest. This
example returns A-Z regardless of case or in your terms, "just the letters."
<%@ Language=VBScri pt %>
<%
Option Explicit
Response.Buffer = True
function getAlpha(str)
dim re, match, matches, reStr
set re = New RegExp
re.Pattern = "[a-z]+"
re.IgnoreCase = True
re.Global = True
set matches = re.Execute(str)
for each match in matches
reStr = reStr & match.value
next
getAlpha = reStr
end function
Response.Write( "Result: " & getAlpha("AaB5b !'C,*cD/d\Ee"))
%>
Response:
Result: AaBbCcDdEe
HTH...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Roland Hall wrote on 03 okt 2004 in
microsoft.publi c.inetserver.as p.general: "Danny" wrote in message news:pw******** **************@ news4.srv.hcvln y.cv.net... :I need an asp command to strip out from a string all extra punctuation :such : as apostrophe, comma, period, spaces dashes, etc etc and just leave : the letters. :
Yes. It's easier to match what you want and just dump the rest. This example returns A-Z regardless of case or in your terms, "just the letters."
I don't think so,
the replace function is much quicker than matching and a loop:
function getAlpha(str)
dim re
set re = New RegExp
re.Pattern = "[^a-z]+"
re.IgnoreCase = True
re.Global = True
getAlpha = re.replace(str, "")
end function
Response.Write "Result: " & getAlpha("AaB5b !'C,*cD/d\Ee")
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)
Danny wrote: I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters.
JScript:
return myString.replac e(/[^a-z]/gi,"")
vbscript :
Use the Replace function and the RegExp object to do the same.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
I use a function for that. There might a slicker way to do it, but this is what I came up with. You can replace each puncuation mark with just an empty string "" instead of the encoding.
Function EncPunc(checkPu nc)
strTmp = checkPunc
strTmp = Replace(strTmp, "'","%39")
strTmp = Replace(strTmp, "%","%25")
strTmp = Replace(strTmp, "&","%26")
strTmp = Replace(strTmp, "#","%23")
strTmp = Replace(strTmp, ";","%3B")
strTmp = Replace(strTmp, "/","%2F")
strTmp = Replace(strTmp, "?","%3F")
strTmp = Replace(strTmp, ":","%3A")
strTmp = Replace(strTmp, "@","%40")
strTmp = Replace(strTmp, "=","%3D")
strTmp = Replace(strTmp, "<","%3C")
strTmp = Replace(strTmp, ">","%3E")
strTmp = Replace(strTmp, """","%22")
strTmp = Replace(strTmp, "{","%7B")
strTmp = Replace(strTmp, "}","%7D")
strTmp = Replace(strTmp, "|","%7C")
strTmp = Replace(strTmp, "\\","%5C")
strTmp = Replace(strTmp, "^","%5E")
strTmp = Replace(strTmp, "~","%7E")
strTmp = Replace(strTmp, "[","%5B")
strTmp = Replace(strTmp, "]","%5D")
strTmp = Replace(strTmp, "`","%60")
EncPunc = strTmp
End Function
*************** *************** *************** *************** **********
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... br******@hotmai l.com wrote on 13 okt 2004 in
microsoft.publi c.inetserver.as p.general: Function EncPunc(checkPu nc) strTmp = checkPunc strTmp = Replace(strTmp, "'","%39") strTmp = Replace(strTmp, "%","%25") strTmp = Replace(strTmp, "&","%26") strTmp = Replace(strTmp, "#","%23")
teststr = "%&#;/?:@=<>""{}|\^~[]`"
Function EncPunc(x)
EncPunc = ""
for i=1 to len(x)
t = mid(x,i,1)
if instr(teststr,t )>0 then t = "%" & asc(t)
EncPunc = EncPunc & t
next
End Function
=============== =============== ====
strTmp = Replace(strTmp, "\\","%5C")
you are mistaken, this is not javascript, but vbscript
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)
Yes, there is a much easier wa to do HTML entity, unfortunatly as far as I
can tell regexps in VB are severely impared!!!
The easy way to do this is to match the char with a regular expresion and
then get the numeric value for the char.
In VB it would look something like
dim reg1 as RegExp
set reg1= new RegExp
reg1.global = true
reg1.pattern="([^a-zA-Z0-9\s])"
text=reg1.repla ce(text,"&" & Asc("$1") & ";"
Unfortunatley in VB you can not pass submatches to a funtion. Submatches
only work inside the expression.
If anyone knows how to pass submatches to a function in a VB RegExp please
let me know.
For now I just call external Perl scripts from VB
by the way, the above in Perl looks like this
$text=~s/([^a-zA-Z0-9\s])/"&".ord($1) .";"/ge;
Aside from being brief, it works!!!
And if we want to check to make sure entities like $ do not get encoded we
can pass to a function that handles this
$text=~s/([^a-zA-Z0-9\s])/encodeHTMLentit ies($1)/ge;
"Bob Roby" wrote: I use a function for that. There might a slicker way to do it, but this is what I came up with. You can replace each puncuation mark with just an empty string "" instead of the encoding.
Function EncPunc(checkPu nc) strTmp = checkPunc strTmp = Replace(strTmp, "'","%39") strTmp = Replace(strTmp, "%","%25") strTmp = Replace(strTmp, "&","%26") strTmp = Replace(strTmp, "#","%23") strTmp = Replace(strTmp, ";","%3B") strTmp = Replace(strTmp, "/","%2F") strTmp = Replace(strTmp, "?","%3F") strTmp = Replace(strTmp, ":","%3A") strTmp = Replace(strTmp, "@","%40") strTmp = Replace(strTmp, "=","%3D") strTmp = Replace(strTmp, "<","%3C") strTmp = Replace(strTmp, ">","%3E") strTmp = Replace(strTmp, """","%22") strTmp = Replace(strTmp, "{","%7B") strTmp = Replace(strTmp, "}","%7D") strTmp = Replace(strTmp, "|","%7C") strTmp = Replace(strTmp, "\\","%5C") strTmp = Replace(strTmp, "^","%5E") strTmp = Replace(strTmp, "~","%7E") strTmp = Replace(strTmp, "[","%5B") strTmp = Replace(strTmp, "]","%5D") strTmp = Replace(strTmp, "`","%60") EncPunc = strTmp End Function
*************** *************** *************** *************** ********** Sent via Fuzzy Software @ http://www.fuzzysoftware.com/ Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
"Bob Roby" wrote:
I use a function for that. There might a slicker way to do it, but this is what I came up with. You can replace each puncuation mark with just an empty string "" instead of the encoding.
Function EncPunc(checkPu nc) strTmp = checkPunc strTmp = Replace(strTmp, "'","%39") strTmp = Replace(strTmp, "%","%25") strTmp = Replace(strTmp, "&","%26") strTmp = Replace(strTmp, "#","%23") strTmp = Replace(strTmp, ";","%3B") strTmp = Replace(strTmp, "/","%2F") strTmp = Replace(strTmp, "?","%3F") strTmp = Replace(strTmp, ":","%3A") strTmp = Replace(strTmp, "@","%40") strTmp = Replace(strTmp, "=","%3D") strTmp = Replace(strTmp, "<","%3C") strTmp = Replace(strTmp, ">","%3E") strTmp = Replace(strTmp, """","%22") strTmp = Replace(strTmp, "{","%7B") strTmp = Replace(strTmp, "}","%7D") strTmp = Replace(strTmp, "|","%7C") strTmp = Replace(strTmp, "\\","%5C") strTmp = Replace(strTmp, "^","%5E") strTmp = Replace(strTmp, "~","%7E") strTmp = Replace(strTmp, "[","%5B") strTmp = Replace(strTmp, "]","%5D") strTmp = Replace(strTmp, "`","%60") EncPunc = strTmp End Function
*************** *************** *************** *************** ********** Sent via Fuzzy Software @ http://www.fuzzysoftware.com/ Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric |
last post by:
I'm sure it's possible, but I can't figure it out...
Given a line of text, I need to convert all of the spaces between quote
marks to an underscore character.
One can consider the end of the line to be a closing quote mark if they
are not balanced.
|
by: Maurice LING |
last post by:
Hi,
I have the following codes:
from __future__ import nested_scopes
import re
from UserDict import UserDict
class Replacer(UserDict):
|
by: Mike Kamermans |
last post by:
I hope someone can help me, because what I'm going through at the moment
trying to edit XML documents is enough to make me want to never edit XML
again.
I'm looking for an XML editor that has a few features that you'd expect
in any editor, except nearly none of them seem to have:
1 - Search and repalce with Regular Expressions.
2 - ...
|
by: Neri |
last post by:
Some document processing program I write has to deal with documents
that have headers and footers that are unnecessary for the main
processing part. Therefore, I'm using a regular expression to go over
each document, find out if it contains a header and/or a footer and
extract only the main content part.
The headers and the footers have no...
|
by: Showjumper |
last post by:
I need a regulr expression that cn be used to find <a> tags with the href
attribute set to mailto:. I need to be to search out all the email addresses
in the text of the pages in a website. So for example i need to be able to
find <a href="mailto:me@mysite.com">Click Here</a> and just get the mailto
portion and then do a replace with an...
| |
by: Lyners |
last post by:
Quick question. I have some java script that looks like this;
imgObj.parentNode.parentNode.childNodes(10).childNodes(0).value=imgObj.parentNode.parentNode.childNodes(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNodes(0).value
This takes a cell in a datagrid (innertext) and subtracts the value of a
text box (value) in another...
|
by: TOXiC |
last post by:
Hi everyone,
First I say that I serched and tryed everything but I cannot figure
out how I can do it.
I want to open a a file (not necessary a txt) and find and replace a
string.
I can do it with:
import fileinput, string, sys
fileQuery = "Text.txt"
sourceText = '''SOURCE'''
|
by: =?Utf-8?B?UGF1bCBXdQ==?= |
last post by:
I need to replace the ascII strings in VC++ source code with unicode
compatiable strings. That is I want to replace "abc" with _T("abc") excluding
the strings in #include line or already in _T("..").
I have regular expression
1. {"(*(\\.*)*)"} // get strings without '_T(' prefix
2. {"(*(\\.*)*)"} //get strings without 'include '...
|
by: Curious |
last post by:
I have another question about Regular Expression. If I use:
if (temp.Contains("Ending") == true)
{
temp =
System.Text.RegularExpressions.Regex.Replace(temp, "Ending",
"Beginning");
}
It seems that while "Ending" is replaced with "Beginning", it also
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |