Solved

String concatenation in loop is bad?

Posted on 2001-08-27
4
232 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
O yeah right, my bad !!
thanks, overlooked
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

14 Experts available now in Live!

Get 1:1 Help Now