2013-09-06 1 views
1

나는 다음과 같이 내가 쓰고 있어요 날짜를 얻기 위해 같은 일, RD, 등등 일 등의 서수를 추가하는 코드 아래에 ..표시 서수는

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

그러나

아래와 같이 나는 결과를 좀하고 싶습니다

enter image description here

답변

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))) 
+0

@ Dominic- 간단한 논리에 감사드립니다. :) – coder

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 

여기에서 서식을 재생할 수 있습니다. 그러나이주의 사항은 하나만의 풍부한 텍스트 상자 또는 컨트롤에서 작동하는 것으로 보입니다.

관련 문제