开发者

Classic ASP class function returning blank

I have inherited a classic asp site which has a fairly robust custom cms. We have recently moved the site across to one of our hosting machines and have recently noticed some issues with getting values frmo functions in an include file (at least thats what I think is happening). There are a number of nested include files but I am sure that they are all being included correctly.

I am sure that the includes are functioning correctly as I have tested changing the path and it displays an error.

Here is the include code:

<!--#include virtual="/admin/core/functions/fncGlobal.asp" -->

The function I am trying to get a value from is:

Function FormatURL(ByRef in_str)
    Dim BadChars, RepChars, NewString, i
    NewString = Trim(in_str)
    NewString = StripNonAlphaNum(NewString)
    NewString = Trim(NewString)
    NewString = Replace(NewString, " ", "-")
    NewString = Replace(NewString, "----", "-")
    NewString = Replace(NewString, "---", "-")
    NewString = Replace(NewString, "--", "-")
    FormatURL = LCase(NewString)
End Function

The function to strip alpha numeric characters:

Function StripNonAlphaNum(inString)
    Dim oRE, strOutput, theString
    If inString <> Null Then    
        inString = Rep开发者_如何学Clace(inString, "'", "")
        inString = Replace(inString, "&amp;", "")
        inString = Replace(inString, "&reg;", "")
        inString = Replace(inString, "&trade;", "")
        inString = Replace(inString, "&copy;", "")
        inString = Replace(inString, "&quote;", "")
        Set oRE = New Regexp
        oRE.Global = True
        oRE.IgnoreCase = True
        oRE.Pattern = "[\W_]"
        strOutput = oRE.Replace(inString, " ")
        StripNonAlphaNum = strOutput
    Else
        StripNonAlphaNum = ""
    End If
End Function

I have tested returning a string from this function but still I get the same blank result.

I am testing the function like this:

Response.Write("Test URL: " & FormatURL("Format URL Title Test"))

The result I get is

Test URL:

Is there something obvious I am doing wrong? I'm not very experienced with ASP.


The issue is this line in StripNonAlphaNum():

If inString <> Null Then

To test for Null, you should use instead

If not IsNull(inString) then

Here is a reference.


probably the line showed below does something wrong:

NewString = StripNonAlphaNum(NewString)

Have you tried to comment out this line to see what happens?

I have comment out that line and it works fine

There is nothing wrong with this code

Module Module1

    Function FormatURL(ByRef in_str)
        Dim BadChars, RepChars, NewString, i
        NewString = Trim(in_str)
        NewString = Trim(NewString)
        NewString = Replace(NewString, " ", "-")
        NewString = Replace(NewString, "----", "-")
        NewString = Replace(NewString, "---", "-")
        NewString = Replace(NewString, "--", "-")
        FormatURL = LCase(NewString)
    End Function


    Sub Main()
        Console.WriteLine(FormatURL("Format URL Title Test"))
        Console.Read()
    End Sub

End Module
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜