Results 1 to 6 of 6

Thread: How to add array items to a string

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    11

    How to add array items to a string

    Hi,

    I have a array named item(3) which contains 4 strings.

    i.e.

    item(0) = hallo
    item(1) = how
    item(2) = are
    item(3) = you?

    Now, i would like these 4 elements in one string named AllTekst.
    I decladed AllTekst as a string, but vb says it cannot cast an 1 dimensional array to type string.

    Can somebody help me?

    Thanks in advance.

    Niels

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: How to add array items to a string

    Hi,

    Must be somethin peculiar in your code. Please post it.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: How to add array items to a string

    Hi
    have you tried something like this?
    Code:
    AllTekst = item(0) & item(1) & item(2) & item(3)

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How to add array items to a string

    no that makes sense... you can't assign an array to a string, because it doesnt know what you REALLY want to do is put all values of the elements of the array into the string.. all VB sees is you trying to say

    string = array

    Code:
    Dim MyString As String
    For i As Integer = 0 To item.GetUpperBound(0)
        MyString  &= item(i)
    Next
    if you are putting a sentence together.. you may want to add spaces in between words..

    MyString &= item(i) & " "

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    11

    Re: How to add array items to a string

    Thank you!, this is what i needed!!
    Last edited by unxpected; Dec 8th, 2004 at 11:43 AM.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: How to add array items to a string

    It may be intentional, but the first word is generally spelled hello rather than hallo.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width