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. tokenzing strings

tokenzing strings

Scheduled Pinned Locked Moved C#
helptutorial
10 Posts 5 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

    using System; public class TokenizeDemo { public static void Main() { int tokenIndex = 0; string values = "#55;xx sterrr,yy city,india"; string[] sites = values.Split(',', '#', ';', ' ', '/', '\0', '&', '-'); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } } } output shows first token is null... how to rectify it... only strings should be tokenized..pls help friends

    the quieter u become more u hear

    L C N 3 Replies Last reply
    0
    • L lawrenceinba

      using System; public class TokenizeDemo { public static void Main() { int tokenIndex = 0; string values = "#55;xx sterrr,yy city,india"; string[] sites = values.Split(',', '#', ';', ' ', '/', '\0', '&', '-'); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } } } output shows first token is null... how to rectify it... only strings should be tokenized..pls help friends

      the quieter u become more u hear

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      lawrenceinba wrote:

      "#55;xx

      The first token is null because of the # as the first character.

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns

      1 Reply Last reply
      0
      • L lawrenceinba

        using System; public class TokenizeDemo { public static void Main() { int tokenIndex = 0; string values = "#55;xx sterrr,yy city,india"; string[] sites = values.Split(',', '#', ';', ' ', '/', '\0', '&', '-'); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } } } output shows first token is null... how to rectify it... only strings should be tokenized..pls help friends

        the quieter u become more u hear

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

        Did you try reading the documentation ? StringSplitOptions.RemoveEmptyEntries is what you need, it's a parameter on some overloads.

        Christian Graus Driven to the arms of OSX by Vista.

        L 1 Reply Last reply
        0
        • C Christian Graus

          Did you try reading the documentation ? StringSplitOptions.RemoveEmptyEntries is what you need, it's a parameter on some overloads.

          Christian Graus Driven to the arms of OSX by Vista.

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

          then how can i bring 55 as token 0 and so on

          the quieter u become more u hear

          C 1 Reply Last reply
          0
          • L lawrenceinba

            then how can i bring 55 as token 0 and so on

            the quieter u become more u hear

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

            Exactly the way I said. I just tested it, and it works, if you use an overload that takes that parameter, 55 is index 0. Did you bother to try it ?

            Christian Graus Driven to the arms of OSX by Vista.

            L 1 Reply Last reply
            0
            • C Christian Graus

              Exactly the way I said. I just tested it, and it works, if you use an overload that takes that parameter, 55 is index 0. Did you bother to try it ?

              Christian Graus Driven to the arms of OSX by Vista.

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

              pls be clear i cant understand.... wat should i do to get token zero for 55

              the quieter u become more u hear

              C 1 Reply Last reply
              0
              • L lawrenceinba

                pls be clear i cant understand.... wat should i do to get token zero for 55

                the quieter u become more u hear

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

                bloody hell. Buy a C# book. Read my article on how to use google. If you can't understand my answer so far, then giving you the precise code will only move you further along the line of having people you work for think you have some sort of clue. And, if you're teaching yourself, refer to point a. Buy a book, and learn to use google, so you don't ask questions that are trivial, and so you know enough to be able to apply the answers when they are given to you. I give up. string values = "#55;xx sterrr,yy city,india"; char[] seperators = { ',', '#', ';', ' ', '/', '\0', '&', '-' }; string[] sites = values.Split(seperators, StringSplitOptions.RemoveEmptyEntries ); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } But, you're pretty damn stupid to not be able to work that out from what I told you, which included a description, and all the keywords you need to find a working example with google, in seconds. I confirmed this when I responded to you.

                Christian Graus Driven to the arms of OSX by Vista.

                L 1 Reply Last reply
                0
                • C Christian Graus

                  bloody hell. Buy a C# book. Read my article on how to use google. If you can't understand my answer so far, then giving you the precise code will only move you further along the line of having people you work for think you have some sort of clue. And, if you're teaching yourself, refer to point a. Buy a book, and learn to use google, so you don't ask questions that are trivial, and so you know enough to be able to apply the answers when they are given to you. I give up. string values = "#55;xx sterrr,yy city,india"; char[] seperators = { ',', '#', ';', ' ', '/', '\0', '&', '-' }; string[] sites = values.Split(seperators, StringSplitOptions.RemoveEmptyEntries ); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } But, you're pretty damn stupid to not be able to work that out from what I told you, which included a description, and all the keywords you need to find a working example with google, in seconds. I confirmed this when I responded to you.

                  Christian Graus Driven to the arms of OSX by Vista.

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

                  im so sorry.... im a minor kid... just writting codes for school work.. again sorry for making u angry

                  the quieter u become more u hear

                  realJSOPR 1 Reply Last reply
                  0
                  • L lawrenceinba

                    im so sorry.... im a minor kid... just writting codes for school work.. again sorry for making u angry

                    the quieter u become more u hear

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #9

                    Maybe you should buy a game console and give up on coding...

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    1 Reply Last reply
                    0
                    • L lawrenceinba

                      using System; public class TokenizeDemo { public static void Main() { int tokenIndex = 0; string values = "#55;xx sterrr,yy city,india"; string[] sites = values.Split(',', '#', ';', ' ', '/', '\0', '&', '-'); foreach (string a in sites) { // Console.WriteLine(a); Console.WriteLine("token number is\t{0} token'd string is\t{1}\tlength of the string is {2}", tokenIndex++, a, a.Length); } } } output shows first token is null... how to rectify it... only strings should be tokenized..pls help friends

                      the quieter u become more u hear

                      N Offline
                      N Offline
                      Najmal
                      wrote on last edited by
                      #10

                      hi.... it bcz the first spliting occured by #.. here left string to # is NULL...

                      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