Help with reformating string using VB.NET

Hi,

How do you reformat a string variable using VB.NET?  For example if S = xxx,yyy,zzz  How do I convert it to S = 'xxx','yyy','zzz' ?

Thanks,

Victor
vcharlesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Something like:
Module Module1
	Private Const data As String = "xxx,yyy,zzz"
	Sub Main()
		Dim temp = data.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
		Dim output = String.Empty
		For i As Integer = 0 To temp.Length - 1 Step 1
			output = If(i = 0, String.Format("'{0}'", temp(i)), String.Format("{0},'{1}'", output, temp(i)))
		Next

		Console.WriteLine(output)
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rgonzo1971Commented:
Hi,

Why not simply use join

Dim  sep As String  = "','"
Dim temp = data.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
Dim output = String.Empty
output =  "'" + String.Join(sep, temp) +"'"

Open in new window


Regards
0
ElrondCTCommented:
Rgonzo, String.Join won't put the quotes in between the items.

I think it's less confusing to write Saige's loop as
		For i As Integer = 0 To temp.Length - 1 Step 1
			output &= "'" & temp(i) & "'"
			If i < temp.Length - 1 Then
				output &= ","
			End If
		Next

Open in new window

but that's a matter of personal preference. Some people really like being able to put everything on a single line.
0
vcharlesAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.