I have a following question, as I am just starting to learn C#.
I have a class defined like this:
public class Piksel
{
public int r;
public int g;
public int b;
}
I then declare an array like so:
Piksel[,] tab2 = new Piksel[32, 32];
Now, I have a *.txt file in the following format:
...
X: 15 , Y: 2 , R: 255 , G: 255 , B: 255
X: 16 , Y: 2 , R: 183 , G: 183 , B: 183
X: 17 , Y: 2 , R: 32 , G: 32 , B: 32
X: 18 , Y: 2 , R: 32 , G: 32 , B: 32
X: 19 , Y: 2 , R: 159 , G: 159 , B: 159
X: 20 , Y: 2 , R: 255 , G: 255 , B: 255
...
I load it into a richTextBox:
OpenFileDialog openF1 = new OpenFileDialog();
openF1.InitialDirectory = "C:\\Users\\Nagash\\Desktop";
openF1.Title = "Wybierz plik z danymi obrazka";
openF1.DefaultExt = "*txt";
openF1.Filter = "Pliki TXT|*txt";
if (openF1.ShowDialog() == System.Windows.Forms.DialogResult.OK && openF1.FileName.Length > 0)
{
richTextBox3.LoadFile(openF1.FileName,RichTextBoxStreamType.PlainText);
}
And now my question: how can I put that data in the tab2 array from the richTextBox. For example, if a line in richTextBox reads
X: 15 , Y: 2 , R: 255 , G: 255 , B: 255
then what i want is the following result:
tab2[15,2].r=255 tab[15,2].g=255 tab[15,2].b=255
I treid fiddling with regular expressions like so:
MatchCollection mc = Regex.Matches(richTextBox3.Text, "[0-9]+");
foreach (Match str in mc)
richTextBox1.Text= richTextBox1.Text + Convert.ToString(str);
But then I am unsure how to tell if a number is 255 or is it 25 and a 5. Also still unsure how to put it into the array.
Thanks for help.