?
Solved

Problems with trim function

Posted on 2007-03-20
3
Medium Priority
?
267 Views
Last Modified: 2010-04-23
In VB.NET
I have a string which looks like this ",,,,,,,,,,,,,,,,,BL8,NW3,BL8)
I need to get rid of the leading commas and whitespaces. Any idea how I do this. Ive had no luck with the Trim function

Seb
0
Comment
Question by:sebastiz
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18759885
combine replace and trim:
replace(ltrim(replace(yourvariable, ",", " ")), " ", ",")
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18759954
string input = ",,,,,,,,,,,,,,,,,BL8,NW3,BL8";
string output = input.TrimStart(new char[] {','});
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18760013
To get rid of the 'leading commas...try this...

yourString=",,,,,,,,,,,,,,,,,BL8,NW3,BL8)"
Dim strNew=yourString.replace(","," ").trim.replace(" ",",")

This will replace all commas with a space, trim the results and then replace the remaining spaces with commas (to 'add' them back in)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

765 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