我有一个标志枚举 (int) 掩码,我需要将其转换为表示星期几的字符串。
说这是完整的字符串和任意掩码
strFullWeek = "MTWtFSs"
strWeekMask = "0100110"
-----------------------
strResult = "-T--FS-"
您建议以什么方式从整周和掩码字符串中获取 strResult?
更新
这是我的“整个上下文”(VB.NET)
<Flags()> Public Enum Week
Monday = 1
Tuesday = 2
Wednesday = 4
Thursday = 8
Friday = 16
Saturday = 32
Sunday = 64
End Enum
Dim mondayOrSunday = Week.Monday Or Week.Sunday
Dim strDays = "MTWtFSs"
Dim strMondayOrSundayBinary = Convert.ToString(
mondayOrSunday, 2).PadRight(7, CChar("0"))
Dim charMondayOrSunday = strDays.Zip(
strMondayOrSundayBinary,
Function(day, mask) If(mask = CChar("1"), day, CChar("-"))).ToArray()
Dim strMondayOrSunday = New String(charMondayOrSunday)
Console.WriteLine("{0} I see as {1}",
mondayOrSunday,
strMondayOrSunday)