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 null entries

removing null entries

Scheduled Pinned Locked Moved C#
regexhelptutorial
4 Posts 3 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.
  • L Offline
    L Offline
    lawrenceinba
    wrote on last edited by
    #1

    string input = "- plum-pear- tyu"; string pattern = "(-)|( )"; string[] substrings = Regex.Split(input, pattern); // Split on hyphens foreach (string match in substrings) { Console.WriteLine("'{0}'", match); } the above code gives out some null tokens.... how to cleanse it.. pls help

    the quieter u become more u hear

    V 1 Reply Last reply
    0
    • L lawrenceinba

      string input = "- plum-pear- tyu"; string pattern = "(-)|( )"; string[] substrings = Regex.Split(input, pattern); // Split on hyphens foreach (string match in substrings) { Console.WriteLine("'{0}'", match); } the above code gives out some null tokens.... how to cleanse it.. pls help

      the quieter u become more u hear

      V Offline
      V Offline
      vaghelabhavesh
      wrote on last edited by
      #2

      lawrenceinba wrote:

      "- plum-pear- tyu";

      Do you see the whitespace in the input string (in between - and p & - and t)? You may want to remove it. string input = "-plum-pear-tyu"; :-)

      Be careful, there is no Undo Button(Ctrl+Z) in life.

      L 1 Reply Last reply
      0
      • V vaghelabhavesh

        lawrenceinba wrote:

        "- plum-pear- tyu";

        Do you see the whitespace in the input string (in between - and p & - and t)? You may want to remove it. string input = "-plum-pear-tyu"; :-)

        Be careful, there is no Undo Button(Ctrl+Z) in life.

        L Offline
        L Offline
        lawrenceinba
        wrote on last edited by
        #3

        no space comes before -

        the quieter u become more u hear

        E 1 Reply Last reply
        0
        • L lawrenceinba

          no space comes before -

          the quieter u become more u hear

          E Offline
          E Offline
          Expert Coming
          wrote on last edited by
          #4

          It looks like it in the code you pasted before. Try this: string[] substrings = Regex.Split(input.Replace(" ", ""), pattern);

          The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

          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