quick string question

quick string question

am 07.12.2005 21:15:37 von josephweiss

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

Re: quick string question

am 07.12.2005 21:21:56 von rdanjou

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))

wrote in message
news:1133986537.790109.306930@g14g2000cwa.googlegroups.com.. .
> 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
>

Re: quick string question

am 07.12.2005 21:29:47 von josephweiss

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%>

Re: quick string question

am 07.12.2005 21:37:41 von reb01501

josephweiss@gmail.com wrote:
> 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

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.

Re: quick string question

am 07.12.2005 21:39:35 von rdanjou

wrote in message
news:1133987387.925126.176310@o13g2000cwo.googlegroups.com.. .
> 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%>

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, ":"))

Re: quick string question

am 07.12.2005 21:41:49 von exjxw.hannivoort

wrote on 07 dec 2005 in microsoft.public.inetserver.asp.db:

> i'm working in .asp. I'm not yet a straight SQL guy.

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)

Re: quick string question

am 07.12.2005 21:47:10 von exjxw.hannivoort

Evertjan. wrote on 07 dec 2005 in microsoft.public.inetserver.asp.db:
> wrote on 07 dec 2005 in microsoft.public.inetserver.asp.db:
>
> response.write( myS );
> %>

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)

Re: quick string question

am 07.12.2005 22:01:10 von josephweiss

Thanks all. Evertjan, your solution was right on the money.