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. string split error ? help please ... [modified]

string split error ? help please ... [modified]

Scheduled Pinned Locked Moved C#
helpquestion
3 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
    Lost User
    wrote on last edited by
    #1

    hi all, i have a string s="05/12-17:25:05-#3 05/12-17:24:56-#3 05/12-17:24:44-#0 05/12-17:24:32-#3"; like this :) and have some code like this in a for loop : string[] dateopened = new string[80]; string[] houropened = new string[80]; string[] whoopened = new string[80]; char[] splitter = { '-',' ' }; char[] myChar ={ ' ' }; while(s.Length>0) dateopened = s.Split(splitter); Console.WriteLine(Convert.ToString(dateopened[i])); houropened = s.Split(splitter); Console.WriteLine(Convert.ToString(houropened[i])); whoopened = s.Split(splitter); Console.WriteLine(Convert.ToString(whoopened[i])); s = s.Remove(0, 17); //after adding these two lines my codes work. s = s.Trim(); } when i run my program i get the output like that : 05/12 05/12 05/12 17:25:05 17:25:05 17:25:05 #3 #3 #3 05/12 05/12 05/12 17:24:56 17:24:56 17:24:56 #3 #3 #3 ... why am i getting each value 3 times ? where am i doing wrong ? what should i do to have each value only ones ? thanks in advance, bye. -- modified at 9:35 Wednesday 14th June, 2006

    R R 2 Replies Last reply
    0
    • L Lost User

      hi all, i have a string s="05/12-17:25:05-#3 05/12-17:24:56-#3 05/12-17:24:44-#0 05/12-17:24:32-#3"; like this :) and have some code like this in a for loop : string[] dateopened = new string[80]; string[] houropened = new string[80]; string[] whoopened = new string[80]; char[] splitter = { '-',' ' }; char[] myChar ={ ' ' }; while(s.Length>0) dateopened = s.Split(splitter); Console.WriteLine(Convert.ToString(dateopened[i])); houropened = s.Split(splitter); Console.WriteLine(Convert.ToString(houropened[i])); whoopened = s.Split(splitter); Console.WriteLine(Convert.ToString(whoopened[i])); s = s.Remove(0, 17); //after adding these two lines my codes work. s = s.Trim(); } when i run my program i get the output like that : 05/12 05/12 05/12 17:25:05 17:25:05 17:25:05 #3 #3 #3 05/12 05/12 05/12 17:24:56 17:24:56 17:24:56 #3 #3 #3 ... why am i getting each value 3 times ? where am i doing wrong ? what should i do to have each value only ones ? thanks in advance, bye. -- modified at 9:35 Wednesday 14th June, 2006

      R Offline
      R Offline
      rah_sin
      wrote on last edited by
      #2

      can u mention what char u r using to split i.e value of splitter. try to use dateopened = s.Split(splitter); Console.WriteLine(Convert.ToString(dateopened[0])); houropened = s.Split(splitter); Console.WriteLine(Convert.ToString(houropened[1])); whoopened = s.Split(splitter); Console.WriteLine(Convert.ToString(whoopened[2])); rahul -- modified at 4:59 Wednesday 14th June, 2006

      1 Reply Last reply
      0
      • L Lost User

        hi all, i have a string s="05/12-17:25:05-#3 05/12-17:24:56-#3 05/12-17:24:44-#0 05/12-17:24:32-#3"; like this :) and have some code like this in a for loop : string[] dateopened = new string[80]; string[] houropened = new string[80]; string[] whoopened = new string[80]; char[] splitter = { '-',' ' }; char[] myChar ={ ' ' }; while(s.Length>0) dateopened = s.Split(splitter); Console.WriteLine(Convert.ToString(dateopened[i])); houropened = s.Split(splitter); Console.WriteLine(Convert.ToString(houropened[i])); whoopened = s.Split(splitter); Console.WriteLine(Convert.ToString(whoopened[i])); s = s.Remove(0, 17); //after adding these two lines my codes work. s = s.Trim(); } when i run my program i get the output like that : 05/12 05/12 05/12 17:25:05 17:25:05 17:25:05 #3 #3 #3 05/12 05/12 05/12 17:24:56 17:24:56 17:24:56 #3 #3 #3 ... why am i getting each value 3 times ? where am i doing wrong ? what should i do to have each value only ones ? thanks in advance, bye. -- modified at 9:35 Wednesday 14th June, 2006

        R Offline
        R Offline
        Roy Heil
        wrote on last edited by
        #3

        It is difficult to know for sure what your problem is, as you did not include all your code. For instance, what is the value of splitter, and what does your loop look like? Try stepping through your code and examining the value of dateopened, houropened, and whoopened. I think you will find that they all contain the same thing, an array with all the dates, all the hours, and all the whoopened. You might try modifying it like this: stringarray = s.Split(splitter); Console.WriteLine(Convert.ToString(stringarray[i*3])); Console.WriteLine(Convert.ToString(stringarray[i*3 +1])); Console.WriteLine(Convert.ToString(stringarray[i*3 +2])); This is assuming that the first iteration of the loop, i is zero. I hope this helps. Roy.

        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