CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    [RESOLVED] ¿Is possible?

    Code:
    MyString =  join({String1 , String2 , String3 , String4, String5},"")
    (it does not work)
    _

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: ¿Is possible?

    Why whould you think that it works ???
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: ¿Is possible?

    Quote Originally Posted by GremlinSA
    Why whould you think that it works ???
    it needs to be:
    Code:
    MyString =  join(ArrayVariable,"")
    and I give the array
    Code:
    {String1 , String2 , String3 , String4, String5}
    This works:
    Code:
    ArrayVariable = {String1 , String2 , String3 , String4, String5}
    MyString =  join(ArrayVariable ,"")
    I have lines like:
    Code:
    MyString =  String1 & String2 & String3 & String4 & String5
    When two of the strings String# are long, that code is very slow. I have lines with a short number of long strings, and a large number of short strings. The time is proportional to the number of small strings, because for each short string, all the long lines are copied again.

    String.Join() works much more faster, but I don't like dividing the code in many lines.
    _

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: ¿Is possible?

    Marraco, have you seen this FAQ:
    http://www.codeguru.com/forum/showthread.php?t=454776

    or the StringArrayConverter thread:
    http://www.codeguru.com/forum/showthread.php?t=454948

    It may help

  5. #5
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: ¿Is possible?

    Quote Originally Posted by HanneSThEGreaT
    Yes, I had read it. (Thanks anyway for caring ). I fact I used String.Concat(data, data, data). Still I would like to know if there are a way, to use a string constant defined in place, in the way I have post.

    For example, is valid to write:
    Code:
    Dim MyArray as String() = {data, data, data}
    but is invalid this line:
    Code:
    String.Join("", {data, data, data} )
    maybe there is a way to do it that way, like:
    Code:
    String.Join("", New String()={data, data, data} )
    '(it does not work)
    Just for curiosity.
    _

  6. #6
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: ¿Is possible?

    Quote Originally Posted by Marraco
    <snip>
    Code:
    String.Join("", New String()={data, data, data} )
    '(it does not work)
    Just for curiosity.
    _
    Remove the =

  7. #7
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: ¿Is possible?

    Quote Originally Posted by Alsvha
    Remove the =
    Perfect. That is.

    PD:I wonder why Microsoft had made it different that in the Dim line.
    _

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: ¿Is possible?

    Quote Originally Posted by Marraco
    PD:I wonder why Microsoft had made it different that in the Dim line.
    _
    With the declaration, if you are going to declare an array like that, you need to give it values, so that the array can be initialised.

    With the Join statement, the Join function expects an array of values, that is why using an already existing array works in there, else, like with your code, you created an array of values on the fly ( inside the Join method ) - you are not assinging those values to a variable or array ( as you did with the declaration ), your just supplying values to the Join method to work properly.

    Does that make sense ¿

    PS, I only now see what you wanted to achieve, sorry

  9. #9
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: ¿Is possible?

    Quote Originally Posted by HanneSThEGreaT
    With the declaration, if you are going to declare an array like that, you need to give it values, so that the array can be initialised.

    With the Join statement, the Join function expects an array of values, that is why using an already existing array works in there, else, like with your code, you created an array of values on the fly ( inside the Join method ) - you are not assinging those values to a variable or array ( as you did with the declaration ), your just supplying values to the Join method to work properly.

    Does that make sense ¿
    I was whining why "=" is not required in:
    Code:
    Join(New String() {data,data,data},"") 'Is not Join(New String() = {data,data,data},"")
    When is required (as is reasonable) in:
    Code:
    Dim MyArray As String() = {data,data,data}
    Quote Originally Posted by HanneSThEGreaT
    PS, I only now see what you wanted to achieve, sorry
    Don't sorry. You give help. Thanks.

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

Featured