• 0

Split String between space in Listbox


Question

I am trying to split a single, long string by spaces into listbox ITEMS. For example:

I need AAAAA-AAAAA BBBBB-BBBBB CCCCCC-CCCCC

to be in listbox as:

AAAAA-AAAAA

BBBBB-BBBBB

CCCCC-CCCCC

 

 

 

In Visual Basic.

 

I know that there must be a simple solution and I have been unable to solve it. Help would be greatly appreciated.

Thank you :)

7 answers to this question

Recommended Posts

  • 0

String.Split is indeed the best way.

 

Then just iterate through your array to insert it into the list box. Foreach will make that easier :)

 

http://msdn.microsoft.com/en-us/library/5ebk1751.aspx <- Foreach usage. It's brilliant :D (just thought I'd add it in case you weren't familiar with the language :))

  • 0

in VB.NET (easily modified for C#) You would do something simple like..
 

        Dim str As String
        str = "AAA-AAA BBB-BBB CCC-CCC"

        ListBox1.Items.AddRange(str.Split(" "))

VB6 is close.. but a little different

 

        Dim str As String
        str = "AAA-AAA BBB-BBB CCC-CCC"
        For Each st In Split(str, " ")
            List1.AddItem (st)
        Next st

The way you do the thing in vb6 with the for each could be used in the .NET languages too, but you save a couple lines, and you are using a pre-existing function to do it.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Chrome is now faster than ever and Google explains how it did it by Sayan Sen Back in June last year, Google touted some great performance improvements for Chrome and shared a blog post explaining in detail how it managed to achieve them. Today, almost exactly a year later, the search giant is back again with another such post as it continues to make performance gains in its Chromium browser. Interestingly, Google is not the only one to make such claims in recent times. Microsoft also highlighted recently how Edge was getting significantly faster. Both Microsoft and Google have cited the Speedometer 3.0 benchmark to test. We recently measured browsing performance during our T-Force DDR5-7200 RAM review, also using Speedometer 3.0. In its blog post, Google says that the development team made significant improvements to memory management and caching. This includes some redesigning effort of the memory layouts for many internal data structures used in components such as DOM, CSS, layout, and painting. Google says that Blink, the rendering engine in Chromium, now "avoids a lot of useless churn" so as to make better use of the CPU caches. In the areas where memory handling previously relied on garbage collection in Oilpan, like the DOM (document object model), the team has expanded that by shifting from using malloc (memory allocation function) to Oilpan entirely. For those wondering, Olipan is the garbage collector in Blink. Some of the memory management and caching improvements Google made are fundamental to good code optimization. If you recall, recently, a senior Microsoft engineer also pointed out many of these issues in apps that slow Windows down. There are also improvements in handling strings within the renderer; the hashing method was updated to rapidhash, which is said to improve performance. For when rendering tasks become inherently expensive, such as computing CSS styles for various elements, Google adds that caching techniques have been enhanced to achieve higher cache hits and fewer misses.
    • Laptop users, this appears to be single-sided so it should fit even in cases with thin slots.
    • Apple wouldn't be what it is today without China either...
    • I am struggling with the game, after playing it again after so many years.... feels so out of space.
  • Recent Achievements

    • Week One Done
      Uranus_enjoyer earned a badge
      Week One Done
    • Week One Done
      jfam earned a badge
      Week One Done
    • First Post
      survivor303 earned a badge
      First Post
    • Week One Done
      CHUNWEI earned a badge
      Week One Done
    • One Year In
      survivor303 earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      428
    2. 2
      +FloatingFatMan
      195
    3. 3
      snowy owl
      191
    4. 4
      ATLien_0
      184
    5. 5
      Xenon
      141
  • Tell a friend

    Love Neowin? Tell a friend!