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

  • Thread starter Thread starter Brad_Ad23
  • Start date Start date
AI Thread Summary
The discussion focuses on modifying the output format of a Visual Basic program that currently generates a string of numbers with an unwanted leading space and comma. The desired output format is a comma-separated string without a leading comma. The solution involves adjusting the code to check if the current index is the first number; if so, it directly assigns the number to the output string. For subsequent numbers, it appends a comma followed by the number. This adjustment effectively eliminates the leading comma, achieving the desired output format.
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:
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Back
Top