Results 1 to 9 of 9

Thread: [RESOLVED] string duplicates help easy one guys i hope

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    102

    Resolved [RESOLVED] string duplicates help easy one guys i hope

    ok string is "hello"

    strdup(100,"hello") only sends the h 1000 times how can i send the hello a 1000 times?????? as to say hellohellohello ect
    Last edited by newbiedoobie1983; Jun 19th, 2017 at 10:22 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: string duplicates help easy one guys i hope

    There is no strdup method that is part of the .NET Framework so either it's your own or from a third party so we have no way of knowing what it does or is supposed to do. You're expecting us to perform magic.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: string duplicates help easy one guys i hope

    If all you're asking, without actually asking, is how to create a String containing a number of copies of another String then you could do this:
    vb.net Code:
    1. Dim finalString = String.Concat(Enumerable.Range(1, copyCount).Select(Function(n) originalString))
    That will create a list of 'copyCount' copies of 'originalString', concatenate them and put the result in 'finalString'.

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: string duplicates help easy one guys i hope

    Quote Originally Posted by jmcilhinney View Post
    There is no strdup method that is part of the .NET Framework so either it's your own or from a third party so we have no way of knowing what it does or is supposed to do. You're expecting us to perform magic.

    Microsoft.VisualBasic.Strings.StrDup Method

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: string duplicates help easy one guys i hope

    I do not think StrDup will use a string. I think it will use only a character.

    I"m posting a less complex method than JMC's (not that his method has anything wrong of course)

    Dim s As String = String.Join("", Enumerable.Repeat("hello", 100))
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: string duplicates help easy one guys i hope

    Quote Originally Posted by Inferrd View Post
    Hmmm... I did search before posting and found nothing, but now I search again and I find that method. Not sure what I did last time but obviously something wrong.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: string duplicates help easy one guys i hope

    Quote Originally Posted by sapator View Post
    I do not think StrDup will use a string. I think it will use only a character.

    I"m posting a less complex method than JMC's (not that his method has anything wrong of course)

    Dim s As String = String.Join("", Enumerable.Repeat("hello", 100))
    I wasn't aware of that Repeat method but it makes sense that it exists. That's an improvement on my effort but you've also taken a step backwards by using String.Join instead of String.Concat. They both join multiple substrings but Join puts a delimiter between each pair. If that delimiter is an empty String then the result is the same, so why require a delimiter at all?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: string duplicates help easy one guys i hope

    Quote Originally Posted by sapator View Post
    I do not think StrDup will use a string. I think it will use only a character.
    As the documentation says, it will accept a String but it will only use the first character of it.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2015
    Posts
    102

    Re: string duplicates help easy one guys i hope

    Very good guys i love the way this went into details about this also the way it was resolved by severalk users in all diff fashions i am very impressed with this forum in general at this point ALSO I ADDED TO ALL REPUTAtion bUT THIS THING WONT LET ME ADD TO jm'S says spread around well i have been so i thx you in words my friend thx you alot

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