Solved

Problems with trim function

Posted on 2007-03-20
3
243 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
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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