how can I add a substring to the lbl_diasemana label?
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
lbl_diasemana.Text = diasemana;
how can I add a substring to the lbl_diasemana label?
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);
lbl_diasemana.Text = diasemana;
Use the Substring
overload which accepts starting index and amount of characters to cut:
lbl_diasemana.Text = diasemana.Substring(0, 3);
You could use the DateTime.Today.ToString(...) method with the appropriate format string and culture like this:
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("pt-BR");
lbl_diasemana.Text = DateTime.Today.ToString("ddd", culture);
https://msdn.microsoft.com/en-us/library/8tfzyc64(v=vs.110).aspx
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0,3);
lbl_diasemana.Text = diasemana;
var culture = new System.Globalization.CultureInfo("pt-BR");
lbl_diasemana.Text = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0, 3);
can be done in 2 lines of code