quick string question

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 [ Mi, 07 Dezember 2005 21:15 ] [ ID #1092286 ]

Re: quick string question

Are you doing this in ASP or in the database:
This works in SQL server:

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

<josephweiss [at] gmail.com> wrote in message
news:1133986537.790109.306930 [at] 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
>
rdanjou [ Mi, 07 Dezember 2005 21:21 ] [ ID #1092287 ]

Re: quick string question

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 [ Mi, 07 Dezember 2005 21:29 ] [ ID #1092288 ]

Re: quick string question

josephweiss [at] 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.
reb01501 [ Mi, 07 Dezember 2005 21:37 ] [ ID #1092289 ]

Re: quick string question

<josephweiss [at] gmail.com> wrote in message
news:1133987387.925126.176310 [at] 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, ":"))
rdanjou [ Mi, 07 Dezember 2005 21:39 ] [ ID #1092290 ]

Re: quick string question

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)
exjxw.hannivoort [ Mi, 07 Dezember 2005 21:41 ] [ ID #1092291 ]

Re: quick string question

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)
exjxw.hannivoort [ Mi, 07 Dezember 2005 21:47 ] [ ID #1092292 ]

Re: quick string question

Thanks all. Evertjan, your solution was right on the money.
josephweiss [ Mi, 07 Dezember 2005 22:01 ] [ ID #1092293 ]
Webserver » microsoft.public.inetserver.asp.db » quick string question

Vorheriges Thema: Problems when passing a sql statement containing non-english characters to a ADO.Recordset object
Nächstes Thema: error 80020009: Either BOF or EOF is True....