PDA

View Full Version : Convert JScript To VBScript


yasiraq
03-09-2009, 05:05 AM
Hi there,

Can you plz convert me the following JScript function into its equivalent VBScript.

-----------------------------------------------------
function GetHTMLDocTitle(s) {
//returns the text between the Title tags

s = "" + s + "";

//this pattern returns the title of an html document.
var re = /(\<TITLE\>)(\s*)(.+)(\s*)(\<\/TITLE\>)/i
var arr = re.exec(s);
return RegExp.$3;
}

--------------------------
Thanks

Old Pedant
03-09-2009, 07:20 AM
You know, you *can* mix JS and VBS on the same ASP page.

You just do:

<%@ Language="VBScript" %>
<script runat=server language="JScript">
function GetHTMLDocTitle(s)
{
//returns the text between the Title tags
s = "" + s + ""; // not sure what this if for, but left it alone

//this pattern returns the title of an html document.
var re = /(\<TITLE\>)(\s*)(.+)(\s*)(\<\/TITLE\>)/i
var arr = re.exec(s);
return RegExp.$3;
}
</script>
<%
' yes, this is now VBS code:
stuffBetweenTitleTags = GetHTMLDocTitle( wherever_you_get_title_from )
...
%>


If you forced me to rewrite it in VBS, this is as close as I could come:

<%
Function GetHTMLDocTitle( s )
Set re = New RegExp
re.Pattern = "^(.*?\<TITLE\>\s*)(.+?)(\s*\<\/TITLE\>.*$)"
re.IgnoreCase = True
GetHTMLDocTitle = re.Replace( s, "$2" )
End Function
%>