Solved

String concatenation in loop is bad?

Posted on 2001-08-27
4
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select only the top record in a left join 13 49
Html Table Looping (part 2) 5 39
Send form to asp server side 6 37
GitHub 1 34
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 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/…

739 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