Forum Moderators: open
In PHP if you want to add to a string rather than replace it, you just use
while (expr) {
$string .= 'this'
}
So if the loop ran 3 times, you would get a string of 'thisthisthis'.
How do you do this in ASP?
All the examples I have found only show loops using response.write at the looping action - I need to set a variable.
[edited by: MavisCruet at 5:53 pm (utc) on Mar. 28, 2008]
myString += "this"
but this way is not very efficient when building long strings, you should use a string builder instead:
VB:
Dim myStringBuilder As StringBuilder = New StringBuilder
myStringBuilder.Append("this")
C#
StringBuilder myStringBuilder = new StringBuilder();
myStringBuilder.Append("this");
Maybe it is better to do in VB because of how it cleans up variables in memory, I don't know it has been about 6 years since I did a project in ASP, but to me that seems like a lot of overhead to reinvent the wheel.
Here is some more info, the bottom post is quite interesting:
[weblogs.asp.net...]