Groups | Blog | Home
all groups > inetserver asp db > december 2005 >

inetserver asp db : quick string question


josephweiss NO[at]SPAM gmail.com
12/7/2005 12:15:37 PM
Is there an easy way to trim everything from the right side of a string
after a certian point?

Here's my string

Product One: 1 Vial auto-shipped every 30 days and your 5th is FREE!


I'd like to trim everything after the : - colon, but her's the
catch...

This is going to be a dynamicly created string. Can I search the
string for the colon and then somehow trim everything after it in each
of the strings that I create?

I just want my string to end up as

Product One:


Many Thanks
josephweiss NO[at]SPAM gmail.com
12/7/2005 12:29:47 PM
i'm working in .asp. I'm not yet a straight SQL guy.

somethign like this...

myStringVariable = "Product One: 1 Vial auto-shipped every 30 days and
your 5th is
FREE!' "

<%=myStringVariable%>
josephweiss NO[at]SPAM gmail.com
12/7/2005 1:01:10 PM
Thanks all. Evertjan, your solution was right on the money.
Raymond D'Anjou
12/7/2005 3:21:56 PM
Are you doing this in ASP or in the database:
This works in SQL server:

declare @str varchar(100)
set @str = 'Product One: 1 Vial auto-shipped every 30 days and your 5th is
FREE!'
select left(@str, charindex(':', @str))

[quoted text, click to view]

Bob Barrows [MVP]
12/7/2005 3:37:41 PM
[quoted text, click to view]

Simple version:

myStringVariable = "Product One: 1 Vial auto-shipped every 30 days and
your 5th is
FREE!' "
ar=split(myStringVariable, ":")
if ubound(ar)>0 then newstring=ar(1)
response.write newstring

It gets a little more complicated if myStringVariable contains more than one
colon. You can loop through the array and rebuild the string if there are
more than two array elements.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Raymond D'Anjou
12/7/2005 3:39:35 PM
[quoted text, click to view]

And I'm not much of an ASP guy.
Anyway, I think this works.
I don't remember if inStr is 1 or 0 based so you may have to adjust just a
bit.

left(myStringVariable, inStr(myStringVariable, ":"))

Evertjan.
12/7/2005 8:41:49 PM
wrote on 07 dec 2005 in microsoft.public.inetserver.asp.db:

[quoted text, click to view]

ASP-vbscript:

<%
myS = "Product One: 1 Vial auto-shipped"

myS = left (myS,instr(myS,":"))

response.write myS
%>

ASP-javascript:

<%
myS = 'Product One: 1 Vial auto-shipped';

myS = myS.replace(/:.*/,':');

response.write( myS );
%>


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Evertjan.
12/7/2005 8:47:10 PM
Evertjan. wrote on 07 dec 2005 in microsoft.public.inetserver.asp.db:
[quoted text, click to view]

Sorry, you wrote AFTER the colon, so:

<%
myS = "Product One: 1 Vial auto-shipped"

myS = mid(myS,instr(myS,":")+1)

response.write myS
%>

ASP-javascript:

<%
myS = 'Product One: 1 Vial auto-shipped';

myS = myS.replace(/[^:]*:/,'')

response.write( myS );
%>




--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
AddThis Social Bookmark Button