reg exp without reg exp 
Author Message
 reg exp without reg exp



Quote:
> hello,

> I want to replace all characters in a string from my
> database that are not numbers or lettters or _
> I want to get rid of all that other characters so that
> only numbers, letters and _ remain, even spaces need
> to be cleared !

> Problem is that i cannot use regular expressions on
> my server => unix server with third party asp software.

> How can i manage this ? (without reg exp ! )

> tnx a lot guys !

(If you're on a unix server, surely you have perl available (which
definitely does have regexps)! You'd be done in no time if you used that.  
But if you must use VBScript ...)

The VB/VBA/VBS/ASP compatible function below should do it.  It will *not*
be fast. Note that if you need to use this in France, you'll want to
change AlphaNum.

Const AlphaNum = _
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

function RemoveNonIdentChar(str)
    dim i, s, c
    s = ""
    for i = 1 to len(str)
        c = mid(str,i,1)
        if instr( AlphaNum, c ) > 0 then
            s = s & c
        end if
    next
    RemoveNonIdentChar = s
end function

--

"The day you get scared by '#ifdef DEBUG' is the day you need to take a
break from the Roguelikes." -- Avital Pilpel



Wed, 25 May 2005 03:38:20 GMT  
 reg exp without reg exp
Hi, Bram
How about something like this:
<CODE>
'Program to demonstrate the removal of all characters in a string
' not in the range A-Z, a-z, 0-9, and not _.

Option Explicit

Dim iaryTranslate(256)    'Global Keep-Character Table
Call InitializeTranslationTable 'Initialize only once

MsgBox KeepSomeChars("N'o]w+_")
MsgBox KeepSomeChars("Now is the time ';;/?.>," & _

 "for all good men to come to the aid of their country." & _
 Chr(0) & Chr(255) & "and then some!")
wscript.quit

Function KeepSomeChars(strInput)
Dim i, straryTemp()
reDim straryTemp(len(strInput))
For i = 1 to len(strInput)
 straryTemp(i) = iaryTranslate(Asc(Mid(strInput,i,1)))
next
KeepSomeChars = join(straryTemp, "")
End Function

Sub InitializeTranslationTable
'Translates the 'keeper' characters to themselves.
'Translates all others to empty strings.
Dim i       'Loop index
For i = 0 to 255
 iaryTranslate(i) = ""
Next
For i = Asc("A") to ASC("Z")
 iaryTranslate(i) = Chr(i)
Next
For i = Asc("a") to ASC("z")
 iaryTranslate(i) = Chr(i)
Next
For i = Asc("0") to ASC("9")
 iaryTranslate(i) = Chr(i)
Next
iaryTranslate(Asc("_")) = "_"
End Sub
</CODE>

-Paul Randall

Quote:

> hello,

> I want to replace all characters in a string from my
> database that are not numbers or lettters or _
> I want to get rid of all that other characters so that
> only numbers, letters and _ remain, even spaces need
> to be cleared !

> Problem is that i cannot use regular expressions on
> my server => unix server with third party asp software.

> How can i manage this ? (without reg exp ! )

> tnx a lot guys !



Wed, 25 May 2005 14:13:02 GMT  
 reg exp without reg exp


: hello,
:
: I want to replace all characters in a string from my
: database that are not numbers or lettters or _
: I want to get rid of all that other characters so that
: only numbers, letters and _ remain, even spaces need
: to be cleared !
:
: Problem is that i cannot use regular expressions on
: my server => unix server with third party asp software.
:
: How can i manage this ? (without reg exp ! )
:
: tnx a lot guys !

Something like this perhaps
(don't know how this is gunna look - just loaded XP - and the copy/paste
from notepad looks funny)


For i = len(str) To 1 Step -1
 If ((asc(ucase(mid(str,i,1))) < 65 Or asc(ucase(mid(str,i,1))) > 90) And _
  (asc(mid(str,i,1)) < 48 Or asc(mid(str,i,1)) > 57) And _
  asc(mid(str,i,1)) <> 95) Then
   str = left(str,i-1) & mid(str,i+1)
 End If
Next
msgbox str



Wed, 25 May 2005 17:24:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reg Exp Question?

2. url validation reg exp

3. reg exp and extended chars

4. vbs IsDate() implemented as reg exp

5. urgent Reg Exp problem

6. reg exp problem

7. First Foray into reg exp and javascript

8. Reg.Exp - steve!-

9. Reg.Exp *repost* - Steve -

10. Reg Exp - STEVE PLZ! :)

11. urgent REG EXP problem!

12. Reg Exp - infinite loop

 

 
Powered by phpBB® Forum Software