How Do I Remove the Leading Comma in a CSV String in Visual Basic?

  • Thread starter Thread starter Brad_Ad23
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around how to format a string of numbers in Visual Basic, specifically focusing on removing a leading comma from a CSV output string. The scope includes programming techniques and code adjustments.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant describes their current output format and expresses the need to eliminate a leading comma in the string of numbers.
  • Another participant suggests a conditional approach to build the output string, where the first element is handled differently to avoid the leading comma.
  • A later reply confirms the suggested solution works, indicating satisfaction with the proposed method.
  • Another participant expresses appreciation for the help provided.

Areas of Agreement / Disagreement

Participants generally agree on the proposed solution to remove the leading comma, with one participant confirming its effectiveness.

Contextual Notes

The discussion does not address potential limitations or assumptions in the proposed code adjustments.

Who May Find This Useful

Readers interested in Visual Basic programming, particularly those dealing with string formatting and output manipulation.

Brad_Ad23
Messages
497
Reaction score
1
I have a visual basic program that outputs strings of numbers to a text file. However currently the output is in the form:

1 2 3 4 5

Note also the space infront of the first number as well. I need for the output to look like:

1,2,3,4,5

However, right now I can only get it to look like:

,1,2,3,4,5

So, is there a way to get rid of that first comma infront of the first number?

Current code for the output:
If (cor > min And cor < max) Then
op = op + 1
For x = 1 To r Step 1
outString = outString + " " + CStr(a(x))
Next
Print #1, outString
outString = ""
End If
 
Computer science news on Phys.org
Maybe I'm missing something but can't you do something like this?

If x = 1 then
outstring = CStr(a(x))
Else
outstring = outstring + "," + " " + CStr(a(x))
Endif
?
 
Ivan Seeking said:
Maybe I'm missing something but can't you do something like this?

If x = 1 then
outstring = CStr(a(x))
Else
outstring = outstring + "," + " " + CStr(a(x))
Endif
?

D'oh! Yep that does it! Thanks! :biggrin:
 
Glad to help. :smile:
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
22K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
17
Views
7K
  • · Replies 6 ·
Replies
6
Views
11K
  • · Replies 34 ·
2
Replies
34
Views
4K