enter image description here

It is necessary to separate the dt_send_daytime column as dd / hh / mm / ss, where dd is the day

I tried it like this

  string dt_str = row["shedule_dt_send_daytime"].ToString(); string[] dt_str_tmp = dt_str.Split(':'); switch (row["time_name_ru"].ToString()) { case "Час": Console.WriteLine(dt_str_tmp[2] + ":" + dt_str_tmp[3]); //мм:сс break; case "Неделя": Console.WriteLine(dt_str_tmp[0] + ":" + dt_str_tmp[1]); //дд:чч break; case "День": Console.WriteLine(dt_str_tmp[1] + ":" + dt_str_tmp[2]); //чч:мм break; case " минут": Console.WriteLine(dt_str_tmp[3]); //сс break; } 

And if in the column name_ru will be another час . How to do it? Please add my code or another example can)

  • what it means to будет ещё час not entirely clear. It is better to give an example of how it was, and how it should turn out. - slippyk
  • If the Час begins with a small час , the Неделя will be with a small неделя - propro17

1 answer 1

In order to check whether the string variables match, you can go in two ways:

1. ToUpper (), ToLower ()

In the first method, you need to take our variable and translate all the characters in one register and compare with the value in the same register.

The String.ToUpper () method returns a copy of the string to uppercase, i.e. "Привет" will be "ПРИВЕТ" .

The String.ToLower () method returns a copy of the string in lower case, i.e. "Привет" will be "привет"

In your case it is:

 switch (row["time_name_ru"].ToString().ToUpper()) { case "ЧАС": ... 
  1. String.CompareTo ()

The String.CompareTo () method compares the two specified String objects (case-insensitive or case-insensitive) and returns an integer that indicates their relative position in the sort order.

In your case, you have to give up switch in favor of if :

 string timeNameRu = row["time_name_ru"].ToString().ToUpper(); if (timeNameRu.CompareTo("ЧАС")==0) { ... } 



UPDATE:

and if there will be a "clock" or "clock"?

The String.Contains () method returns a value indicating whether the specified string contains the value of the substring passed as a parameter.

 string timeName = row["time_name_ru"].ToString().ToUpper(); if (timeNameRu.Contains("ЧАС") == 0) { ... } 
  • and if there will be a часы or часов - propro17
  • You need to take the date from the dt_send_daytime column. Ie 1:1:4:0 every week, every Monday, at one o'clock, 4 minutes it should work. Can I do this? - propro17