Link to home
Start Free TrialLog in
Avatar of sebastiz
sebastiz

asked on

Problems with trim function

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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dstanley9
dstanley9

string input = ",,,,,,,,,,,,,,,,,BL8,NW3,BL8";
string output = input.TrimStart(new char[] {','});
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)