Solved

String concatenation in loop is bad?

Posted on 2001-08-27
4
243 Views
Last Modified: 2012-06-27
I have read that it is bad to do string concatenation in loops on the MSDN.  

Now i need a VB script subroutine to remove blank spaces from a character string.

E.g. input parameter is  "I am a boy"
The required output is "Iamaboy"

What is then the best technique to use?
0
Comment
Question by:leowlf
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
turbosig earned 50 total points
ID: 6428252
Replace(expression, find, replacewith[, start[, count[, compare]]])

--> Replace(strText," ","")

This will search for a space and replace it.

The last 3 parameters are optional.
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6428806
Use Trim/Ltrim/Rtrim function
e.g.
Dim MyVar
MyVar = LTrim("   vbscript ")   ' MyVar contains "vbscript ".
MyVar = RTrim("   vbscript ")   ' MyVar contains "   vbscript".
MyVar = Trim("   vbscript ")   ' MyVar contains "vbscript".
0
 
LVL 2

Expert Comment

by:turbosig
ID: 6429208
jitqanguly,

That will only remove "empty" spaces from the ends, it will not remove inner spaces.

-->  Good call though, that will allow you to not have to replace those.
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6429312
O yeah right, my bad !!
thanks, overlooked
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now