Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > trouble with LEFT function

Reply
Thread Tools

trouble with LEFT function

 
 
Middletree
Guest
Posts: n/a
 
      01-04-2008
My results after doing some stuff are going to have names separated by
commas. Example:

James & Beth Williams John & Mary Smith Ross & Rachel Gellar Willy & Wanda
Wonka


But the number of names is variable, so I put in commas between each one.
Then I end up with:

, James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar, Willy &
Wanda Wonka

This is almost what I need, except that first comma. To get rid of it, I
tried doing a replace of the first character on the left, like this:

strFullName = Replace(strFullName,Left(strFullName,1),"")

However, this is yielding weird results.

What am I doing wrong in my replace function?


 
Reply With Quote
 
 
 
 
Middletree
Guest
Posts: n/a
 
      01-04-2008
I am not familiar with Mid.

At any rate, I got this error when I tried it:

Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/dev/groupevents.asp, line 59, column 17
Mid(string, start[, length])


 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      01-04-2008
"Middletree" <> wrote in message
news:...
> I am not familiar with Mid.
>
> At any rate, I got this error when I tried it:
>
> Microsoft VBScript compilation (0x800A03EE)
> Expected ')'
> /dev/groupevents.asp, line 59, column 17
> Mid(string, start[, length])
>


Consider reading the manual:-

http://msdn2.microsoft.com/en-us/lib...7y(VS.85).aspx

Mid(string, start[, length])

--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      01-04-2008
Middletree wrote on 04 jan 2008 in
microsoft.public.inetserver.asp.general:

> My results after doing some stuff are going to have names separated by
> commas. Example:
>
> James & Beth Williams John & Mary Smith Ross & Rachel Gellar Willy &
> Wanda Wonka
>
>
> But the number of names is variable, so I put in commas between each
> one. Then I end up with:
>
> , James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar,
> Willy & Wanda Wonka
>
> This is almost what I need, except that first comma. To get rid of it,
> I tried doing a replace of the first character on the left, like this:
>
> strFullName = Replace(strFullName,Left(strFullName,1),"")
>
> However, this is yielding weird results.
>
> What am I doing wrong in my replace function?


I suppose you assume VBscript, which is not the only ASP language.

Try:

Dim t
t = ", James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar"
t = Replace(t,", ","",1,1)

Explanation:
replacing the comma+space: ", "
with an empty string: ""
starting at the first letter: 1
and only once: 1

===============

Or using mid():

Dim t
t = ", James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar"
t = mid(t,3)

Explanation:
new string t starts at the 3rd letter of the old one

===============

using ASP-j[ava]script is also a good option
making one line regex possible:

var t;
t = ', James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar';
t = t.replace(/^, /,'');

Explanation:
replace
from the start: ^
the comma+space: ", "
non global: so only once
with an empty string ''

===============

I would urge you to read the specs on functions you use and not assume
them.

Download script56.chm:
<http://www.microsoft.com/downloads/>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Middletree
Guest
Posts: n/a
 
      01-04-2008
> Dim t
> t = ", James & Beth Williams, John & Mary Smith, Ross & Rachel Gellar"
> t = Replace(t,", ","",1,1)
>


This did the trick. I had no idea Replace function allowed a starting ans
stopping point. Thanks very much.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does .rjust() work and why it places characters relative toprevious one, not to first character - placed most to left - or to left sideof screen? crispy Python 6 08-20-2012 12:45 PM
left shift operator behaves like left rotate when the operand is a variable. pc C Programming 2 06-08-2011 06:58 PM
Help on table align on left of page vs left hanging indent =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= XML 2 07-16-2007 11:46 AM
Left panel on left hand side of desktop on windows xp wish to get rid of Bun Mui Computer Support 1 09-14-2004 03:40 AM
can't reset the left value of a DIV using document.getElementById(thisDiv).style.left = howFarLeft; lawrence Javascript 13 09-04-2004 09:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57