-2

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;
MethodMan
  • 18,625
  • 6
  • 34
  • 52

4 Answers4

1

Use the Substring overload which accepts starting index and amount of characters to cut:

lbl_diasemana.Text = diasemana.Substring(0, 3);
Deadzone
  • 793
  • 1
  • 11
  • 33
1

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

Matt
  • 126
  • 6
0
var culture = new System.Globalization.CultureInfo("pt-BR");
var diasemana = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0,3);
lbl_diasemana.Text = diasemana;
David P
  • 2,027
  • 3
  • 15
  • 27
0
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

MethodMan
  • 18,625
  • 6
  • 34
  • 52
  • You could probably do it one line if you want: lbl_diasemana.Text = new System.Globalization.CultureInfo("pt-BR").DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek).Substring(0, 3); – David P Jun 20 '17 at 20:53