trouble with LEFT function

Discussion in 'ASP General' started by Middletree, Jan 4, 2008.

  1. Middletree

    Middletree Guest

    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?
    Middletree, Jan 4, 2008
    #1
    1. Advertising

  2. Middletree

    Middletree Guest

    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])
    Middletree, Jan 4, 2008
    #2
    1. Advertising

  3. "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/library/sx7b3k7y(VS.85).aspx

    Mid(string, start[, length])

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jan 4, 2008
    #3
  4. Middletree

    Evertjan. Guest

    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)
    Evertjan., Jan 4, 2008
    #4
  5. Middletree

    Middletree Guest

    > 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.
    Middletree, Jan 4, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    407
  2. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help on table align on left of page vs left hanging indent

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jul 10, 2007, in forum: XML
    Replies:
    2
    Views:
    1,002
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Jul 16, 2007
  3. pc
    Replies:
    2
    Views:
    1,312
    crisgoogle
    Jun 8, 2011
  4. lawrence
    Replies:
    13
    Views:
    297
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
  5. Stevo
    Replies:
    10
    Views:
    285
    Thomas 'PointedEars' Lahn
    Mar 27, 2008
Loading...

Share This Page