Forum Moderators: open

Message Too Old, No Replies

Substring

How do you do substring with ASP?

         

webworker us

6:47 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



I am trying to do a substring on the contents of one of my database cells. I am currently trying:

hold = Mid(cstr(other("Material")),0,2)

where other("Material") is the reference to the cell.

Any suggestions would be greatly appriciated.

qlipoth

9:07 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



In ASP, Mid is 1-based

Try:

hold = Mid(cstr(other("Material")),1,2)
or
hold = Mid(cstr(other("Material")),1,3)
if you are trying to get 3 characters.

webworker us

12:19 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Thanks. I'm so used to starting with zero from C++ and Java I didn't even think of it.

qlipoth

8:12 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Personally, I like Left(String, length) instead of mid... I'm lazy enough that one extra parameter bothers me.

mattglet

1:38 am on Jun 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Left() and Mid() are apples and oranges. Mid() is way more powerful. It's not about laziness, it's about necessity.

giggle

8:44 am on Jun 28, 2005 (gmt 0)

10+ Year Member



If you want the end of a string you don't have to specify the last parameter with the MID verb.

E.g. to get "MICK" from strDescription = "FATMICK" you just need to specify:

strWhoIsFat = MID(strDescription,4)

Just thought that I'd share that, it has saved me a little bit of time now and then.

Mick

mrMister

1:52 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. I'm so used to starting with zero from C++ and Java I didn't even think of it.

Have you thought about using JScript instead of VBScript? It'll save you from all sorts of problems like this. Just put the following line at the top of your page...

<%@ Page Language="JScript"%>

webworker us

6:24 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



I've thought of it, but decided to keep my stuff to one language. I have other people that edit the page, and use things like ASPmaker, and they would have difficulties if I use JScript.