Solved

String concatenation in loop is bad?

Posted on 2001-08-27
4
265 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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