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

  • Thread starter Brad_Ad23
  • Start date
In summary, the conversation discusses the issue of formatting output in a visual basic program. The desired output is a string of numbers separated by commas, but the current output has a comma before the first number. The solution is to add a conditional statement in the code to exclude the comma for the first number.
  • #1
Brad_Ad23
502
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
  • #2
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
?
 
  • #3
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:
 
  • #4
Glad to help. :smile:
 

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

What is VisualBasic?

VisualBasic is a programming language created by Microsoft in 1991. It is designed to be user-friendly and easy to learn, making it a popular choice for beginners and non-programmers.

What can I use VisualBasic for?

VisualBasic can be used to create a variety of applications, including desktop software, games, and web applications. It is also commonly used for automating tasks in Microsoft Office programs.

How do I get started with VisualBasic?

To get started with VisualBasic, you will need to download and install a development environment, such as Microsoft Visual Studio. There are also many online resources and tutorials available for learning the basics of the language.

What are the advantages of using VisualBasic?

One of the main advantages of VisualBasic is its easy-to-use syntax and user-friendly interface, which makes it accessible to beginners. It also has a large community of users and developers, so there is a lot of support and resources available.

Are there any limitations to using VisualBasic?

While VisualBasic is a great language for beginners, it may not be suitable for more complex or advanced projects. It also has a smaller user base compared to other programming languages, so it may be more difficult to find support or resources for more specific needs.

Similar threads

Replies
7
Views
2K
Replies
2
Views
2K
Replies
2
Views
1K
Replies
2
Views
22K
Replies
2
Views
3K
Replies
6
Views
10K
Back
Top