Re: String

Tech-Archive recommends: Speed Up your PC by fixing your registry



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)

.



Relevant Pages

  • Re: String
    ... "ID" of type Int ... "Product" of type String ... Dim items As Generic.List ... remove the last comma. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)