tags:

views:

916

answers:

4

what's the asp equivalent to php's .= when concatenating strings?? oh and i'm referring to asp NOT asp.net.

argh...i meant to specify that i'm in a for loop. so i want to know the equivalent for .= (in php) not standard concatenation.

example below:

For Each Item In Request.Form
    If (Item = "service") then 
        For x=1 To Request.Form(item).Count
            service = "&service="&Request.Form(Item)(x)
        Next
    End If
Next
+6  A: 

In VBScript:

Variable = Variable & "something more"

In JScript I believe you can use:

variable += "something more";

Specifically:

service = service & "&service=" & Request.Form(Item)(x)

assuming you want your result to look something like...

&service=blah1&service=blah2&service=blah3

Though you may need to URL encode your Request.Form(Item)(x) values because any "&" (and other characters) could really muck up what you are trying to do. Also be careful when using unsanitized input like this directly from an HTML form, its very dangerous.

cfeduke
If you concatenate large strings and your application needs to be performance tuned, look at concatenation to be your first area to improve. A simple VB6 or C++ COM library which emulates the .NET StringBuilder class will greatly improve performance.
cfeduke
Or simply use Join on an array and avoid the VB6/C++ marlarky
AnthonyWJones
A: 

argh...i meant to specify that i'm in a for loop. so i want to know the equivalent for .= (in php) not standard concatenation.

If you are concatenating strings there is no shorthand in VBScript for ASP 2.5 or 3.0; you will have to suffer with repeating yourself or invoking a function that does, whether you are in a loop or not.
cfeduke
It makes no difference whether you are in a loop or not. If the language has no shortcut operator you just re-assign the original variable as cfeduke describes. Your worry about loops is leading you astray. Loops are not interesting here.
Cheekysoft
A: 

I can't remember for certain, but &= should work in ASP. I know it works in VB.Net. Although I can't recall if that worked in asp. If that doesn't work, the only solution is a = a & b.

Kibbee
I don't think so.
FlySwat
A: 

It looks like you have found your answer, but here is a good reference that relates to your question: http://www.design215.com/toolbox/asp.php

Brad