There is an array of string
elements for example:
mas[0] = "1_30092016_12"; mas[1] = "2_30092016_13"; mas[2] = "3_30022016_14"; mas[3] = "4_30012016_15";
How to select items from it by date (the second part of the name after _)?
There is an array of string
elements for example:
mas[0] = "1_30092016_12"; mas[1] = "2_30092016_13"; mas[2] = "3_30022016_14"; mas[3] = "4_30012016_15";
How to select items from it by date (the second part of the name after _)?
string[] mas = new string[] { "1_30092016_12", "2_30092016_13", "3_30022016_14", "4_30012016_15" }; foreach (var i in mas) { string[] myArray = i.Split('_'); Console.WriteLine(myArray[1]); // второй элемент массива содержит строки с датами }
Here's an example for you and String.Format
and Linq
and work with DateTime
, learn about health
mas.Where(x=>x.Contains(string.Format("_{0}_", (new DateTime(2016, 9, 30)).ToString("ddMMyyyy"))));
private void SearchDate() { string[] mas = new string[] { "1_30092016_12", "2_30092016_13", "3_30022016_14", "4_30012016_15" }; string search = "30012016"; for (int i = 0; i < mas.Length; i++ ) { if (mas[i].Contains(search)) { MessageBox.Show(mas[i]); } } }
You can use LINQ. In the simplest case, selecting an item by date will look like this:
var m = from s in mas where s.Contains("30022016") select s; textBox1.Text = m.FirstOrDefault();
string.Join
- GrundySource: https://ru.stackoverflow.com/questions/557037/
All Articles