Re: String and Class

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



shapper wrote:
Hello,

I have a class, named MyClass, with 2 properties: Name and Text.

And I have a string as follows: "dog, new york, france , car"
Note that the words are separated by commas and that sometimes there
are spaces before and after a comma.

I want to get all words, i.e. "dog", "new york", "france" and "car",
and add them to a generic.list(of MyClass) assigning them to property
"Text".

How can I do this?

Thanks,
Miguel


Something like this (note, untested code, may not compile!

Assuming VB .Net...

Dim myList As ArrayList

Dim myString As String = "dog, new york, france , car"
Dim mySplitStringArray As String() = myString.Split(",")

Dim myTempString As String
Dim i As Integer
For Each myTempString In mySplitStringArray
MyClass o = new MyClass()
MyClass.Text = myTempString.Trim()
mylist.Add(MyClass)
Next


Hope that helps,

RB.

.



Relevant Pages

  • Re: how do you pass string value from a form to class
    ... >no the string value in the from is hard set ... >Dim MyClass As OutAddIn ...
    (microsoft.public.vb.general.discussion)
  • Re: Assigning a type to a variable at runtime
    ... That will probably keep the taste of the apples and the pears ... > contains a string. ... for the above example I would want the equivalent of "dim ... > x.gettype would return 'MyClass' so I would want the equivalent of "dim y ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Casting from interface to its base type
    ... Dim _myClass as New MyClass(of String) ... For each _kvp as KeyPairValue(of String, IMyInterface) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Casting from interface to its base type
    ... Dim _myClass as New MyClass(of String) ... For each _kvp as KeyPairValue(of String, IMyInterface) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Parse string
    ... dim str as string ... dim car as string ... I want to parse a string character by character just like an array. ...
    (microsoft.public.excel.programming)