Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Removing white spaces from an ArrayList

Removing white spaces from an ArrayList

Scheduled Pinned Locked Moved C#
helpdatabasedata-structures
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rizwan Rathore
    wrote on last edited by
    #1

    Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006

    C W C 3 Replies Last reply
    0
    • R Rizwan Rathore

      Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006

      C Offline
      C Offline
      cshivaprasad
      wrote on last edited by
      #2

      friend this may resolve, ur first problem.. private void parseString(String x) { string tempstr; int i=0,len,flag=0; tempstr=""; len=x.Length; while(i < len) { if(x[i]!= ' ') { tempstr = tempstr + x[i]; flag = 0; } else { if(flag == 0) { str.Add(tempstr); tempstr = ""; flag = 1; index++; } } i++; } str.Add(tempstr); } In this str is arraylist If u have still some doubt, mail me ShivaJee

      1 Reply Last reply
      0
      • R Rizwan Rathore

        Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006

        W Offline
        W Offline
        Wjousts
        wrote on last edited by
        #3

        In .NET 2.0 you can use the StringSplitOptions.RemoveEmptyEntries with the String.Split function. Otherwise when you load up your ArrayList just check if the strings contain only white space:if (myString.Trim()="") // string is nothing but white space so don't add it to your arraylist
        To convert back to a string can't you just iterate through the ArrayList and add each entry to a string, or even a StringBuilder? -- modified at 16:53 Tuesday 9th May, 2006

        1 Reply Last reply
        0
        • R Rizwan Rathore

          Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Use foreach to iterate over the array and a stringbuilder and ToString ( if you're not using a string in your foreach ) to pass each object through the stringbuilder to build up your string. Christian Graus - Microsoft MVP - C++

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups