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