我有下面的代码来添加诸如st,rd,th之类的序数......
Private ordinals As String() = New String() {"", "st", "nd", "rd", "th", "th", _
"th", "th", "th", "th", "th", "th", _
"th", "th", "th", "th", "th", "th", _
"th", "th", "th", "st", "nd", "rd", _
"th", "th", "th", "th", "th", "th", _
"th", "st"}
为了得到约会,我写的如下:
Dim D As DateTime = Me.PresentDate.Value.ToString("MM-dd-yyyy")
Dim todate As String = D.Day.ToString() + ordinals(D.Day)
结果:
第五
但我想得到如下所示的结果
答案 0 :(得分:1)
为什么不首先使用上标字符?
Dim ordinals = {"", "ˢᵗ", "ⁿᵈ", "ʳᵈ", "ᵗʰ", "ᵗʰ", _
"ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", _
"ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", _
"ᵗʰ", "ᵗʰ", "ᵗʰ", "ˢᵗ", "ⁿᵈ", "ⁿᵈ", _
"ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", "ᵗʰ", _
"ᵗʰ", "ˢᵗ"}
Dim D = DateTime.Now
Dim todate = D.Day.ToString() + ordinals(D.Day) ' todate = 6ᵗʰ
或创建一个简单的查找字典:
Dim ordinals = {"", "st", "nd", "rd", "th", "th", _
"th", "th", "th", "th", "th", "th", _
"th", "th", "th", "th", "th", "th", _
"th", "th", "th", "st", "nd", "rd", _
"th", "th", "th", "th", "th", "th", _
"th", "st"}
Dim supers = "abcdefghijklmnopqrstuvwxyz".Zip("ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖXʳˢᵗᵘᵛʷˣʸᶻ", AddressOf Tuple.Create) _
.ToDictionary(Function(t) t.Item1, Function(t) t.Item2)
Dim D = Date.Now
Dim todate = D.Day.ToString() + String.Join("", ordinals(D.Day).Select(Function(c) supers(c)))
答案 1 :(得分:1)
如果您尝试在富文本框中显示此内容,则可以执行以下操作。假设您在表单上有一个富文本框,并且已经延迟了您的一系列序数。在表单的load事件中添加以下内容:
Dim D As DateTime = CDate(Now.ToString("MM-dd-yyyy"))
Dim todate As String = D.Day.ToString() + ordinals(D.Day)
With RichTextBox1
.SelectionFont = New Font("Lucinda Console", 12)
.SelectedText = D.Day.ToString()
.SelectionCharOffset = 5
.SelectedText = ordinals(D.Day)
End With
从这里你可以玩格式化。然而,作为一个警告,这似乎只适用于从一个
派生的富文本框或控件