可能重複:
Is there an easy way in .NET to get 「st」, 「nd」, 「rd」 and 「th」 endings for numbers?格式數量的排名位置
有什麼已經內置到格式化數作爲一個排名位置C#?
通過 「排行榜上的位置」 是一個均值[ 「ST」, 「第二,」 RD」, 「日」],例如:(1日,2日,3日,4日)
我知道它會很容易寫這個的延伸,我只是想知道,如果已經有一些在語言來迎合。
乾杯
可能重複:
Is there an easy way in .NET to get 「st」, 「nd」, 「rd」 and 「th」 endings for numbers?格式數量的排名位置
有什麼已經內置到格式化數作爲一個排名位置C#?
通過 「排行榜上的位置」 是一個均值[ 「ST」, 「第二,」 RD」, 「日」],例如:(1日,2日,3日,4日)
我知道它會很容易寫這個的延伸,我只是想知道,如果已經有一些在語言來迎合。
乾杯
沒有,有沒有內置的用於這一目的。如果不知道它的相關,但考慮到文化差異,如果您跨越語言/文化。
謝謝Jamiec。在考慮文化時,我正在考慮將序數說明符存儲在資源文件中,以便我們可以爲特定文化指定特定的說明符。你認爲這是一個解決方案? – 2010-08-04 15:54:36
我已更正。請參閱dup如上述評論中所述的授權問題。
不是開箱即用的;然而,正如你所提到的,擴展很容易。
public static string ConvertToRankingPosition(this int value)
{
var digit = value % 10;
return value != 11 && digit == 1 : value + "st" :
value != 12 && digit == 2 : value + "nd" :
value != 13 && digit == 3 : value + "rd" :
value + "th"
}
看一看這樣的:http://stackoverflow.com/questions/69262/is-there-an-easy-way-in-net-to-get-st-nd -rd和-TH-結局換號。 – 2010-08-04 15:47:03
重複http://stackoverflow.com/questions/20156/is-there-an-easy-way-to-create-ordinals-in-c – sgriffinusa 2010-08-04 15:47:12
感謝您的鏈接夥計。很有幫助。 – 2010-08-04 15:53:36