Reputation: 2028
I need to loop through each day of the week (monday tues...) and compare the day to a string. I know I can manually add each day of week to a string array, but that's not what prefer. Any help would be much appreciated.
Update
Thanks to Michael Liu the code goes as follows: First on top of page:
Imports System.Globalization
then:
For Each d In CultureInfo.CurrentCulture.DateTimeFormat.DayNames
If d.ToString = "my string" Then
End If
Next
Upvotes: 0
Views: 1842
Reputation: 4007
You don't need a loop:
Dim dayToTest as String = "Monday"
If [Enum].GetNames(GetType(DayOfWeek)).ToList().Contains(dayToTest) Then
' etc
End If
Upvotes: 1
Reputation: 55359
Import System.Globalization
and loop through the CultureInfo.CurrentCulture.DateTimeFormat.DayNames
(localized) or CultureInfo.InvariantCulture.DateTimeFormat.DayNames
(English) array.
Upvotes: 1