Forum Moderators: open

Message Too Old, No Replies

Help with Code

Trying to get a substring

         

Emmett

9:59 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



I've been programming for a while but I'm still fairly new to ASP. This is probably a fairly stupid question but I've been wrestling with it all day. I keep getting an error on the call to Substring in the code below.


<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>

<%

PageName = Request.ServerVariables("SCRIPT_NAME")
Response.Write(PageName)
Response.Write("<br>")

Output = PageName.Substring(1,3);
Response.Write(Output)
%>

The message I'm getting is: Object doesn't support this property or method

I've tried lots of variations and posted the most simple, it's almost like the server doesn't know what a string is. Do I need to define it somewhere?

Thanks for looking.

mattglet

10:31 pm on Mar 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the Mid function [devguru.com].

Emmett

11:08 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



Thanks for the response.

The MID function does work fine for me in VBScript. The Problem I'm running into is the code snippet will be included in JScript pages.

I may end up trying to convert my entire site to VB or C# but was hoping to avoid it.

My ideal objective would be to find something that works like strchr in C. The idea is to get the URL and figure out what directory the script is being ran from so I can have a dynamic link menu.

Example:
mysite.com/widget/pagex would return links that relate to widgets
mysite.com/foo/pagex would return links that relate to foo

Emmett

12:14 am on Mar 10, 2005 (gmt 0)

10+ Year Member



I converted to VB and used InStr. Works like a charm.

Thanks again!

mattglet

2:22 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could just split the string into an array, and read the array(1) value.

musicales

4:58 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



In the javascript I think the substring should be lower case as in substring now Substring. then it should work.