有没有一种简单的方法可以将数字1,2,3,...转换为"第一","第二","第三",......,并且这样我可以给函数一个语言并且有它会返回我正在定位的语言的正确形式吗?标准C++(stl或boost OK),MFC或ATL,win32 api或者我可以从某个地方下载的小型,单用且免费的库.谢谢.
有没有人知道将"第一","第十"和"第一百"之类的单词转换为数字等价的方法?
样品:"第一" - > 1,"第二" - > 2,"第十" - > 10,"百分之一" - > 100
任何算法都足够了,但我在C#中写这个.
编辑
它不漂亮,一次只能用一个单词,但它适合我的目的.也许有人可以改进它,但我没时间.
public static int GetNumberFromOrdinalString(string inputString)
{
string[] ordinalNumberWords = { "", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth" };
string[] ordinalNumberWordsTens = { "", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth", "seventieth", "eightieth", "ninetieth" };
string[] ordinalNumberWordsExtended = {"hundredth", "thousandth", "millionth", "billionth" };
if (inputString.IsNullOrEmpty() || inputString.Length < 5 || inputString.Contains(" …
Run Code Online (Sandbox Code Playgroud) for($ rank = 0; $ rank <100; $ rank ++){printf("your rank:%d%s",$ rank,$ suffix); }
是否存在gettext函数来将$ suffix本地化为当前语言并返回,例如:
Your rank: 0th
Your rank: 1st
Your rank: 2nd
Your rank: 3rd
Your rank: 4th
Run Code Online (Sandbox Code Playgroud)
如果当前语言环境是英语,并且当语言环境设置为其他语言时,无论其他语言中正确的"序数"形式的数字是什么?
谢谢.
如何在LINQ表达式中创建所选项目时获取序号位置?例如:
var alphaordinals = new string[] { "A", "B", "C", "D", "E" }; // etc.
var q = from car in datacontext.Cars
select new InventoryItem
{
Name = car.Name,
Price = car.Price,
UIElement = "Car " + car.Id.ToString() + ???
};
return q.ToList();
Run Code Online (Sandbox Code Playgroud)
我希望Cars列表的InventoryItem.UIElement如下:
Car 27 A
Car 28 B
Car 31 C
Car 48 D
Run Code Online (Sandbox Code Playgroud)
等等
是否有一种简单的方法以第1,第2,第3,......格式显示日期的日期部分?我怀疑通过自定义日期时间格式字符串没有这样做的方法(我会很高兴错了),所以有人实现了这样做的方法吗?
我在html表中有一行只包含图像.(这恰好也是第一行).这些图像也用于点击事件.在尝试处理click事件时,我可以找到它的父<td>
元素(即元素).但我想知道它在表格行中的相对序数(<tr
>).
我想要一个将填充此地图内容的函数:
{:1 "first" :2 "second" :3 "third" :4 "fourth" ... :100 "one-hundredth" ...}
Run Code Online (Sandbox Code Playgroud)
所以我可以做类似的事情
(println "This is the " (:3 {... :3 "third" ...}) " item in the sequence")
> This is the third item in the sequence
Run Code Online (Sandbox Code Playgroud)
是否有现有的Clojure库可以做到这一点?
(如果有更好的方法来描述这种功能 - 请告诉我)
是否有内置的VB.NET函数将数字格式化为序数或者我必须自己编写?
有没有什么优雅的方法如何在js/coffee中以单词格式获得序数?像这样的东西:
ordinalInWord(1) # => "first"
ordinalInWord(2) # => "second"
ordinalInWord(5) # => "fifth"
Run Code Online (Sandbox Code Playgroud) ordinals ×10
c# ×2
.net-3.5 ×1
algorithm ×1
c++ ×1
clojure ×1
coffeescript ×1
datetime ×1
function ×1
gettext ×1
html-table ×1
javascript ×1
jquery ×1
linq ×1
linq-to-sql ×1
localization ×1
mfc ×1
mysql ×1
numbers ×1
numeric ×1
ordinal ×1
php ×1
sql ×1
string ×1
vb.net ×1