Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Remove numeric characters from a string

I have this code which should remove the numeric characters - but I keep getting the error:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/piac/test-remove.asp, line 8

Dim initialString As String = "XXXXXX-06-X-1234"
------------------^

I also saw another solution which I tried:

<%
Reg = New RegExp
Reg.Global=true
Reg.IgnoreCase=true
Reg.Pattern="([0-9]$[-\s]*[0-9]$)" 'this is the important part - it finds the string of characters

Function RemoveNumbers(objString)
     RemoveNumbers=Reg.Replace(objString, "")
End Function
%>

<p>Address with no numbers: <%=RemoveNumbers("Sport utca 3")%></p>

but that returned the error:

Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method


All I want to do is take a value for a field from a DB that is a text string, remove the numbers and then render the field without the numbers.

Any help would be apreciated.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<%
Dim initialString As String = "XXXXXX-06-X-1234"
Dim nonNumericCharacters As New System.Text.RegularExpressions.Regex(@"\D")
Dim numericOnlyString As String = nonNumericCharacters.Replace(initialString, String.Empty)
%>
</head>
 
<body>
<%=numericOnlyString%>
</body>
</html>

Open in new window

0
aotyehel
Asked:
aotyehel
  • 4
  • 4
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

Dim initialString As String = "XXXXXX-06-X-1234"
is vb.net.
in vbs, you need to put 2 lines:


Dim initialString
initialString = "XXXXXX-06-X-1234"
0
 
aotyehelAuthor Commented:
That partially helped...

but how do I deal with the other lines?

The attached code is what I have.

The following error is returned:

Microsoft VBScript compilation error '800a0408'

Invalid character

/piac/test-remove.asp, line 11

nonNumericCharacters = New System.Text.RegularExpressions.Regex(@"\D")
----------------------------------------------------------------^



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<%
Dim initialString 
initialString = "XXXXXX-06-X-1234"
Dim nonNumericCharacters 
nonNumericCharacters = New System.Text.RegularExpressions.Regex(@"\D")
Dim numericOnlyString 
numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty)
%>
</head>
 
<body>
<%=numericOnlyString%>
</body>
</html>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
remove the @. that is for .net to make sure the \ inside the string would be use as such, and not as escape character. which is not not needed in vbscript
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aotyehelAuthor Commented:
Error

Microsoft VBScript runtime error '800a01fa'

Class not defined: 'System'


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<%
Dim initialString 
initialString = "XXXXXX-06-X-1234"
Dim nonNumericCharacters 
nonNumericCharacters = New System.Text.RegularExpressions.Regex("\D")
Dim numericOnlyString 
numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty)
%>
</head>
 
<body>
<%=numericOnlyString%>
</body>
</html>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>nonNumericCharacters = New System.Text.RegularExpressions.Regex("\D")
that is part of the .net framework, which I fear you cannot use directly from vbs like that.


but, there is some alternative for vbs:
http://msdn.microsoft.com/en-us/library/ms974570.aspx

0
 
aotyehelAuthor Commented:
OK. Then I need to change my question.

Can someone write me some code for classic ASP with VBScript that can take a string and remove (or replace with spaces) any numbers then return the altered string.

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Dim initialString As String
initialString = "XXXXXX-06-X-1234"

Dim i

for i = 0 to 9
  initialString = replace(initialString , "" & i, " ")
next

0
 
aotyehelAuthor Commented:
Final code:

<%
Dim initialString
initialString = "XXXXXX-06-X-1234"

Dim i

for i = 0 to 9
  initialString = replace(initialString , "" & i, " ")
next

%>

No 'As String' in VBScript
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now