3 Replies - 339 Views - Last Post: 26 September 2012 - 04:34 PM Rate Topic: -----

#1 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Store a matrix first row in a array

Posted 26 September 2012 - 01:39 PM

i have a textbox and the input to the textbox is 1x4 matrix. (Eg: 1 1 -1 1) and i am trying to stored in the array
a[i] (i.e, a[0]=1;a[1]=1;a[2]=-1;a[3]=1; ) to perform encoding and decoding;

b[i]= Convert.ToInt32(textBox1.Text);



The above is storing only one value into the array. i am trying to store the complete row of the matrix to store in a array at once, is it possible?

Is This A Good Question/Topic? 0
  • +

Replies To: Store a matrix first row in a array

#2 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: Store a matrix first row in a array

Posted 26 September 2012 - 02:07 PM

I don't know a way to do it all at once, but you could split the string using something this:

string[] elems = textBox1.Text.Split(" ".toCharArray());



Then use Convert.ToInt32() on each of the strings in the elems array. Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: Store a matrix first row in a array

Posted 26 September 2012 - 02:30 PM

Actually, there is a one-liner if you're using Visual C# 2010 or later:

int[] mat = (textBox1.Text.Split(" ".ToCharArray())).Select(elem => Int32.Parse(elem)).ToArray();



You have have 'using System.Linq;' at the top of your file.
Was This Post Helpful? 0
  • +
  • -

#4 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Re: Store a matrix first row in a array

Posted 26 September 2012 - 04:34 PM

Thank you very much it worked...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1