1

我有以下代码用于添加诸如 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)

结果:

第 5 名

但我想得到如下所示的结果

在此处输入图像描述

4

2 回答 2

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)))
于 2013-09-06T07:51:18.107 回答
1

如果您尝试在富文本框中显示此内容,则可以执行以下操作。这假设您在表单上有一个富文本框并且已经声明了您的序数字符串。在表单的加载事件中添加以下内容:

 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

从这里您应该能够使用格式。然而,作为一个警告,这似乎只适用于富文本框或从一个派生的控件

于 2013-09-06T08:08:58.257 回答