"mingle" variables with string literals

N

nick

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

is something similar possible in ASP?
 
B

Bob Lehmann

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

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

Bob Lehmann
 
N

nick

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}"?
 
B

Bob Barrows [MVP]

nick said:
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).
 
B

Bob Lehmann

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
 
N

nick

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.
 
B

Bob Barrows [MVP]

nick said:
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?
 
B

Bob Lehmann

Oh, you're a real piece of work.

Except the answer isn't "NO" You said -
I showed you something similar.

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
 
N

nick

Oh, you're a real piece of work.


Except the answer isn't "NO" You said -


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????
 
B

Bob Lehmann

Well I guess if you only code in vbscript
ummm.... No.
Which is effectively what you are doing in PHP.
I understood your question exactly as it was asked. Maybe you should work on
that.

*PLONK*

Bob Lehmann
 
N

nick

ummm.... No.


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!
I understood your question exactly as it was asked.

Whatever.
 
A

Anthony Jones

nick said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top