Re: String
- From: Alexey Smirnov <alexey.smirnov@xxxxxxxxx>
- Date: Tue, 11 Sep 2007 14:33:31 -0700
On Sep 11, 10:52 pm, shapper <mdmo...@xxxxxxxxx> wrote:
Hello,
I have a class, Item, with 2 properties:
"ID" of type Int
"Product" of type String
I create a variable which is a Generic.List(Of Item):
Dim items As Generic.List(Of Item)
items.Add(10, "Book")
items.Add(20, "Car")
...
I want to create a string from this generic list that holds all the
items products separated by a comma:
MyItems = "Book,Car,..."
How can I do this?
The easiest way I can find is to create a for loop. But then I need to
remove the last comma.
Anyway, I am not sure if this is the best way to do this.
Thanks,
Miguel
Miguel, you can use StringBuilder
Dim MyItems As System.Text.StringBuilder = New
System.Text.StringBuilder()
Dim i As Integer
For i = 0 To items.Count - 1
MyItems.Append(list(i))
MyItems.Append(",")
Next
If MyItems.Length > 0 Then
MyItems = MyItems.Substring(0, MyItems.Length - 1)
End If
(it's similar to one from Stephen)
.
- References:
- String
- From: shapper
- String
- Prev by Date: Re: List Box scrolling
- Next by Date: Out-of-process State Management Session Cleanup
- Previous by thread: Re: String
- Next by thread: Out-of-process State Management Session Cleanup
- Index(es):
Relevant Pages
|