2 Replies - 303 Views - Last Post: 28 December 2012 - 05:27 PM Rate Topic: -----

#1 g0gy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-November 12

splitting a string into an array

Posted 28 December 2012 - 04:22 PM


 Random r = new Random();

 int x = r.Next(1, 64);
                Console.WriteLine(x);
                int b = 2;
                string binValue = Convert.ToString(x, B)/>;
                Console.Write("bin: " + binValue.ToString());
                string[] a = new string[binValue.Length];
                
                    for (int i = 0; i < binValue.Length; i++)
                    {
                        a[i] = binValue.Substring(i, 1);
                        Console.WriteLine(a[i]);

                    }




i used substring method to split the string into the array but it didn't display the first and last values so i don't know why??

can anyone help????

Is This A Good Question/Topic? 0
  • +

Replies To: splitting a string into an array

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2015
  • View blog
  • Posts: 3,041
  • Joined: 21-June 11

Re: splitting a string into an array

Posted 28 December 2012 - 04:41 PM

The code is working fine - you're misinterpreting the output because you do not print a newline after printing binValue on line 7.

PS: You don't need to call ToString on a string.
Was This Post Helpful? 0
  • +
  • -

#3 g0gy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-November 12

Re: splitting a string into an array

Posted 28 December 2012 - 05:27 PM

thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1