我有下面的代码来添加序号,例如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)结果:
第五位
但是我想得到如下的结果

发布于 2013-09-06 07:51:18
为什么不首先使用上标字符呢?
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)))发布于 2013-09-06 08:08:58
如果您试图在富文本框中显示此内容,则可以执行以下操作。这假设您在窗体上有一个丰富的文本框,并且已经删除了序数字符串。在表单的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从这里开始,您应该能够处理格式。但是,作为警告,这似乎只适用于从一个文本框或控件派生的富文本框或控件。
https://stackoverflow.com/questions/18651463
复制相似问题