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. tokenize string

tokenize string

Scheduled Pinned Locked Moved C#
tutorial
6 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 strInput= "plotno 55,xx street,yy city";
    char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
    string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
    foreach (string a in strTemp)
    {

            Console.WriteLine(" token'd string is\\t{0}\\t", a);
    

    the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks

    the quieter u become more u hear

    P A 2 Replies Last reply
    0
    • L lawrenceinba

      string strInput= "plotno 55,xx street,yy city";
      char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
      string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
      foreach (string a in strTemp)
      {

              Console.WriteLine(" token'd string is\\t{0}\\t", a);
      

      the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks

      the quieter u become more u hear

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Use a Regular Expression instead.

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Use a Regular Expression instead.

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

        but input will be from array list... is it possible to pass array list as input to regex

        the quieter u become more u hear

        A 1 Reply Last reply
        0
        • L lawrenceinba

          string strInput= "plotno 55,xx street,yy city";
          char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
          string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
          foreach (string a in strTemp)
          {

                  Console.WriteLine(" token'd string is\\t{0}\\t", a);
          

          the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks

          the quieter u become more u hear

          A Offline
          A Offline
          ABitSmart
          wrote on last edited by
          #4

          in the example which you have provided, the string has been split based on your delimiters i.e. ',' and ' '. Do you want the delimiters also to appear in the output ?

          L 1 Reply Last reply
          0
          • A ABitSmart

            in the example which you have provided, the string has been split based on your delimiters i.e. ',' and ' '. Do you want the delimiters also to appear in the output ?

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

            hmmm. yes .. can u help me

            the quieter u become more u hear

            1 Reply Last reply
            0
            • L lawrenceinba

              but input will be from array list... is it possible to pass array list as input to regex

              the quieter u become more u hear

              A Offline
              A Offline
              ABitSmart
              wrote on last edited by
              #6

              Have you tried Regex.Split ? With the input pattern like "(,)|(#)|(;)|( )|(/)|(&)|(-)" string pattern = "(,)|(#)|(;)|( )|(/)|(&)|(-)"; string[] splitOutput = Regex.Split(input, pattern); (the option for ; in the pattern is replaced by the smiley in the post :) )

              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