Solved

Problems with trim function

Posted on 2007-03-20
3
220 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
Comment Utility
combine replace and trim:
replace(ltrim(replace(yourvariable, ",", " ")), " ", ",")
0
 
LVL 25

Expert Comment

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

Expert Comment

by:sirbounty
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now