在Delphi中将月份名称转换为号码? [英] Convert month name to number in Delphi?

查看:118
本文介绍了在Delphi中将月份名称转换为号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些内置的Delphi(XE2)/ Windows方法将月份名称转换为1-12;而不是循环通过(TFormatSettings。)LongMonthNames [] 我自己?

Is there some built-in Delphi (XE2)/Windows method to convert month names to numbers 1-12; instead of looping through (TFormatSettings.)LongMonthNames[] myself?

推荐答案

您可以使用 StrUtils 中的 IndexStr ,返回 -1 如果没有找到字符串,例如

You can use IndexStr from StrUtils, returns -1 if string not found e.g.

Caption := IntToStr(
  IndexStr(FormatSettings.LongMonthNames[7], FormatSettings.LongMonthNames) + 1);

编辑:

为避免投射和区分大小写的问题,您可以使用 IndexText 如图所示:

Function GetMonthNumber(Const Month:String):Integer; overload;
begin
   Result := IndexText(Month,FormatSettings.LongMonthNames)+1
end;

这篇关于在Delphi中将月份名称转换为号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆