2017-05-25 109 views
0

我可以轉換日期CDate參數英文字母日期RDLC轉換日期爲字母數字

如:轉換'08.12.1994''Eighth December : Nineteen Hundred Ninety-Four'

+1

不,我認爲你不能輕易做到這一點。您寧願將其轉換爲代碼並傳遞已轉換的參數。 – Pikoh

+1

@Pikoh所以,是否有任何內置的方法的C#將int轉換爲字母? – Brainiac

+0

我知道沒有內置的東西。你可以試試[Humanizer](https://github.com/Humanizr/Humanizer) – Pikoh

回答

1

如果你保證DD.MM.YYYY格式的日期,這個VB代碼可能是像你想要的東西。

Function ConvertDate(ByVal date As String) As String 
    Dim textDate As String = "" 
    Dim nDay As Integer = CInt(date.Split(".")(0)) 
    Dim nMonth As Integer = CInt(date.Split(".")(1)) 
    Dim nYear As Integer = CInt(date.Split(".")(2)) 
    Dim hundreds As Integer = 0 
    Dim notHundreds As Integer = 0 

    //Convert day to text. 
    Select Case (nDay) 
     Case 1 
      textDate += "First" 
     //Fill in cases 2-30 
     Case 31 
      textDate += "Thirty-First" 
    End Select 

    //Add your separator. 
    textDate += " " 

    //Convert the month to text. 
    Select Case (nMonth) 
     Case 1 
      textDate += "January" 
     //Finn in cases 2-11 
     Case 12 
      textDate += "December" 
    End Select 

    //Add your separator. 
    textDate += " : " 

    //Split the year. 
    hundreds = nYear/100 
    notHundreds = nYear - 100 * hundreds 

    //Add the hundreds part of the date if there is one. 
    If hundreds <> 0 Then 
     textDate += NumberUnder100ToText(hundreds) 
     textDate += "Hundred " 
    End If 

    //Add the not hundreds part if there is one. 
    If notHundreds <> 0 Then 
     textDate += NumberUnder100ToText(notHundreds) 
    End If 

    //Remove extra trailing space if present. 
    textDate = textDate.Trim() 

    Return textDate 
End Function 

Function NumberUnder100ToText(ByVal number As Integer) As String 
    Dim text As String = "" 

    If number < 20 Then 
     //Covers 1 to 19 
     Select Case (number) 
      Case 0 //Do nothing 
       text = "" 
      Case 1 
       text = "One" 
      //Cases 2-18 
      Case 19 
       text = "Nineteen" 
     End Select 
    Else 
     //Add the 10s place 
     Select Case (number/10) 
      Case 2 
       text = "Twenty" 
      //Cases 3-8 
      Case 9 
       text = "Ninety" 
     End Select 

     //Add the 1s place 
     If (number Mod 10 <> 0) Then 
      text += "-" 
      text += NumberUnder100ToText(number Mod 10) 
     End If 
    End If 

    Return text 
End Function