hello there is a code. I loop through the child pictures of the grid. In pictures, the name of the type is "Q1_2"; Numbers can be from 0 to 14. So I create 2 random numbers from 0 to 14 and I want to check if the number in the name before the _ sign corresponds to Row and the last number in the name after the _ sign corresponds to Column then do some actions.

 int Row = random.Next(0, 14); int Column = random.Next(0,14); foreach (var child in chidrens) { i = child as Image; if (i is Image) { //Π’ΠΎΡ‚ Ρ‚ΡƒΡ‚ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ числа ΠΈΠ· ΠΈΠΌΠ΅Π½ΠΈ ΠΈ ΡΡ€Π°Π²Π½ΠΈΡ‚ΡŒ с Ρ€Π°Π½Π΄ΠΎΠΌΠ½Ρ‹ΠΌΠΈ числами } else { //ΠΈΠ½Π°Ρ‡Π΅ } } 

I think to do so

 Regex regex = new Regex(@"\d{2}_\d{2}"; 

but I understand it will look for 2 digits I have and one digit is what to do

 Regex regex = new Regex(@"\d{1}_\d{1}"; 

Tell me how to do it in a normal way.

  • Can you change the name of the pictures? Make it such 001002 Then it will be possible to read the first and last 3 digits from the line - your numbers. - codename0082016
  • only numbers cannot be used to make a name. Therefore, I added a letter - Sasuke
  • then use q001002 and take the following numbers. - codename0082016
  • why is the number from the name of the control not clear? Can you make an object from a class ?: the name of the control - its number - its second number. obj_Q1_2.name obj_Q1_2_.n1 obj_Q1_2_.n2 and take your data from it - codename0082016
  • one
    In addition to Name controls also have such a property as Tag , you can write in it the numbers of pictures you need, without any initial letters and other unnecessary garbage. You can make a through numbering of pictures or make a numbering from a two-digit number - for the row and column numbers. - Bulson

1 answer 1

Make it easier. Create an array of 3 elements. For example, string [] mass = new string [3]; mass = i.Split ('_', 'Q'); You cut the file name into 3 elements and then compare the elements of the array. 0 is empty 1 is the first number 2 is the second number. And all) And then another regulars sues)) already)