[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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
0
sebastiz
Asked:
sebastiz
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
combine replace and trim:
replace(ltrim(replace(yourvariable, ",", " ")), " ", ",")
0
 
dstanley9Commented:
string input = ",,,,,,,,,,,,,,,,,BL8,NW3,BL8";
string output = input.TrimStart(new char[] {','});
0
 
sirbountyCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now