"mingle" variables with string literals

Discussion in 'ASP General' started by nick, Jan 25, 2008.

  1. nick

    nick Guest

    Hi in PHP you can do this:
    echo "you're logged in as {$username}"

    is something similar possible in ASP?
    nick, Jan 25, 2008
    #1
    1. Advertising

  2. nick

    Bob Lehmann Guest

    Presuming VBScript and a value having been assigned to username.....

    Response.Write ("you're logged in as " & username)

    Bob Lehmann

    "nick" <> wrote in message
    news:...
    > Hi in PHP you can do this:
    > echo "you're logged in as {$username}"
    >
    > is something similar possible in ASP?
    Bob Lehmann, Jan 26, 2008
    #2
    1. Advertising

  3. nick

    nick Guest

    On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    > Presuming VBScript and a value having been assigned to username.....
    >
    > Response.Write ("you're logged in as " & username)


    Yes I know that, but is it possible to do something like "you're
    logged in as {username}"?

    >
    > Bob Lehmann
    >
    > "nick" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > Hi in PHP you can do this:
    > > echo "you're logged in as {$username}"

    >
    > > is something similar possible in ASP?
    nick, Jan 26, 2008
    #3
  4. nick wrote:
    > On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    >> Presuming VBScript and a value having been assigned to username.....
    >>
    >> Response.Write ("you're logged in as " & username)

    >
    > Yes I know that, but is it possible to do something like "you're
    > logged in as {username}"?
    >

    Frankly, I thought that his answer implied that you couldn't (Bob is a man
    of few words).

    What you CAN do is use the Replace function to substitute values for
    placeholders:

    s="you're logged in as {$username}"
    username = "something"
    Response.Write Replace(s, "{$username}", username)

    .... which is likely to be what PHP is doing for you behind the scenes (just
    guessing here - I've never used PHP).
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jan 26, 2008
    #4
  5. nick

    Bob Lehmann Guest

    >> but is it possible to do something like "you're logged in as {username}"?

    No. In VBSscript, variables embedded in a string cannot be parsed as they
    can in PHP.

    Since VB doesn't use that nasty '$' prefix for variables, how would it
    differentiate variables from text?

    Bob Lehmann

    "nick" <> wrote in message
    news:...
    > On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    > > Presuming VBScript and a value having been assigned to username.....
    > >
    > > Response.Write ("you're logged in as " & username)

    >
    > Yes I know that, but is it possible to do something like "you're
    > logged in as {username}"?
    >
    > >
    > > Bob Lehmann
    > >
    > > "nick" <> wrote in message
    > >
    > > news:...
    > >
    > >
    > >
    > >
    > >
    > > > Hi in PHP you can do this:
    > > > echo "you're logged in as {$username}"

    > >
    > > > is something similar possible in ASP?

    >
    Bob Lehmann, Jan 26, 2008
    #5
  6. nick

    nick Guest

    On Jan 27, 12:32 am, "Bob Barrows [MVP]" <>
    wrote:
    > nick wrote:
    > > On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    > >> Presuming VBScript and a value having been assigned to username.....

    >
    > >> Response.Write ("you're logged in as " & username)

    >
    > > Yes I know that, but is it possible to do something like "you're
    > > logged in as {username}"?

    >
    > Frankly, I thought that his answer implied that you couldn't (Bob is a man
    > of few words).
    >


    Er.. if he really is a man of few words, all he had to say was "NO".

    I think he just assumed I am a complete noob to ASP

    > What you CAN do is use the Replace function to substitute values for
    > placeholders:
    >
    > s="you're logged in as {$username}"
    > username = "something"
    > Response.Write Replace(s, "{$username}", username)
    >


    Thanks but no thanks.
    nick, Jan 27, 2008
    #6
  7. nick wrote:
    > On Jan 27, 12:32 am, "Bob Barrows [MVP]" <>
    > wrote:
    >> nick wrote:
    >>> On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    >>>> Presuming VBScript and a value having been assigned to
    >>>> username.....

    >>
    >>>> Response.Write ("you're logged in as " & username)

    >>
    >>> Yes I know that, but is it possible to do something like "you're
    >>> logged in as {username}"?

    >>
    >> Frankly, I thought that his answer implied that you couldn't (Bob is
    >> a man of few words).
    >>

    >
    > Er.. if he really is a man of few words, all he had to say was "NO".
    >
    > I think he just assumed I am a complete noob to ASP


    Well, given the question, along with the lack of context, is it so hard to
    understand why that assumption would be made?


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jan 27, 2008
    #7
  8. nick

    Bob Lehmann Guest

    Oh, you're a real piece of work.

    >> all he had to say was "NO".


    Except the answer isn't "NO" You said -
    >> is something similar possible in ASP?


    I showed you something similar.

    >> I think he just assumed I am a complete noob to ASP


    Not sure where you are the noob scale, buddy. But I think you would be hard
    pressed to find someone, even moderately skilled, asking the question you
    did. Especially since you knew exactly what you meant when you asked it.

    Bob Lehmann


    >>> is something similar possible in ASP?

    "nick" <> wrote in message
    news:...
    > On Jan 27, 12:32 am, "Bob Barrows [MVP]" <>
    > wrote:
    > > nick wrote:
    > > > On Jan 26, 12:13 pm, "Bob Lehmann" <> wrote:
    > > >> Presuming VBScript and a value having been assigned to username.....

    > >
    > > >> Response.Write ("you're logged in as " & username)

    > >
    > > > Yes I know that, but is it possible to do something like "you're
    > > > logged in as {username}"?

    > >
    > > Frankly, I thought that his answer implied that you couldn't (Bob is a

    man
    > > of few words).
    > >

    >
    > Er.. if he really is a man of few words, all he had to say was "NO".
    >
    > I think he just assumed I am a complete noob to ASP
    >
    > > What you CAN do is use the Replace function to substitute values for
    > > placeholders:
    > >
    > > s="you're logged in as {$username}"
    > > username = "something"
    > > Response.Write Replace(s, "{$username}", username)
    > >

    >
    > Thanks but no thanks.
    Bob Lehmann, Jan 27, 2008
    #8
  9. nick

    nick Guest

    On Jan 28, 7:52 am, "Bob Lehmann" <> wrote:
    > Oh, you're a real piece of work.
    >
    > >> all he had to say was "NO".

    >
    > Except the answer isn't "NO" You said -
    >
    > >> is something similar possible in ASP?

    >
    > I showed you something similar.


    No you didn't. You showed me how to do simple string concatenation,
    when it should've been obvious to anyone that I was asking for a more
    advanced syntax/technique of doing the same thing?

    Well I guess if you only code in vbscript you will have trouble
    understanding my question in the first place.

    "you're logged in as {$username}"???? Is that legal????
    nick, Jan 28, 2008
    #9
  10. nick

    Bob Lehmann Guest

    >>> Well I guess if you only code in vbscript
    ummm.... No.

    >>> You showed me how to do simple string concatenation,

    Which is effectively what you are doing in PHP.

    >>> understanding my question in the first place.

    I understood your question exactly as it was asked. Maybe you should work on
    that.

    *PLONK*

    Bob Lehmann

    "nick" <> wrote in message
    news:...
    > On Jan 28, 7:52 am, "Bob Lehmann" <> wrote:
    > > Oh, you're a real piece of work.
    > >
    > > >> all he had to say was "NO".

    > >
    > > Except the answer isn't "NO" You said -
    > >
    > > >> is something similar possible in ASP?

    > >
    > > I showed you something similar.

    >
    > No you didn't. You showed me how to do simple string concatenation,
    > when it should've been obvious to anyone that I was asking for a more
    > advanced syntax/technique of doing the same thing?
    >
    > Well I guess if you only code in vbscript you will have trouble
    > understanding my question in the first place.
    >
    > "you're logged in as {$username}"???? Is that legal????
    Bob Lehmann, Jan 28, 2008
    #10
  11. nick

    nick Guest

    On Jan 28, 2:09 pm, "Bob Lehmann" <> wrote:
    > >>> Well I guess if you only code in vbscript

    >
    > ummm.... No.
    >
    > >>> You showed me how to do simple string concatenation,

    >
    > Which is effectively what you are doing in PHP.


    Simple = "blah blah" . $var
    Bit more advance = "blah blah {$var}" or "blah blah $var"

    I asked: Can you do "blah blah {$var}"?
    You "answered": Yes, how about "blah blah " & var

    LOL!

    >
    > >>> understanding my question in the first place.

    >
    > I understood your question exactly as it was asked.


    Whatever.
    nick, Jan 28, 2008
    #11
  12. "nick" <> wrote in message
    news:...
    > On Jan 28, 2:09 pm, "Bob Lehmann" <> wrote:
    > > >>> Well I guess if you only code in vbscript

    > >
    > > ummm.... No.
    > >
    > > >>> You showed me how to do simple string concatenation,

    > >
    > > Which is effectively what you are doing in PHP.

    >
    > Simple = "blah blah" . $var
    > Bit more advance = "blah blah {$var}" or "blah blah $var"
    >
    > I asked: Can you do "blah blah {$var}"?
    > You "answered": Yes, how about "blah blah " & var
    >
    > LOL!
    >



    Actually, Nick, you asked for something 'similar'. In the VBScript and
    JScript string concatenation is the closest you'll get to performing a
    'similar' operation to the one you described.

    Fundementally in PHP strings are treated as expressions that need evaluating
    whereas in VBScript and JScript they are primitive values that require no
    further processing.

    Therefore to perform something similar in the common script languages used
    by ASP you need to make your string appear as an expression that needs
    evaluating. The simplest way to do that is break it up into a series of
    concatentations.

    Is there some nuance of PHP behaviour we are missing here that means that
    this approach doesn't meet your needs?


    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jan 29, 2008
    #12
    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. Harri Pesonen

    String literals in Java

    Harri Pesonen, May 28, 2004, in forum: Java
    Replies:
    59
    Views:
    14,911
    Jim Cochrane
    Jun 2, 2004
  2. Pete Elmgreen

    character literals and string

    Pete Elmgreen, Nov 24, 2004, in forum: Java
    Replies:
    3
    Views:
    4,658
  3. Purush
    Replies:
    4
    Views:
    1,643
    Purush Rudrakshala
    Apr 13, 2005
  4. Replies:
    4
    Views:
    876
    Roedy Green
    Nov 21, 2005
  5. John Goche
    Replies:
    8
    Views:
    16,449
Loading...

Share This Page