各種語言常用的一句話判斷代碼_其它綜合

來源:互聯網
上載者:User

判斷漢字

複製代碼 代碼如下:

if (System.Text.Encoding.GetEncoding("gb2312").GetBytes("中").Length == 2) // C#
if (escape(str).indexOf("%u") < 0) // JavaScript

判斷數字

複製代碼 代碼如下:

Number.as(v) // ezj
Number.asInt(v) // ezj 判斷整數
 

判斷純數字

複製代碼 代碼如下:

Number.asPureNumber(v) // ezj 判斷純數字(不能有加號或減號、小數點)
System.Text.RegularExpressions.Regex.IsMatch(str, @"^\d+$") // C#

判斷閏年

複製代碼 代碼如下:

if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) // C#、JavaScript
if ((year mod 4 = 0) and (year mod 100 <> 0)) or (n mod 400 = 0) then // ASP

判斷頁數

複製代碼 代碼如下:

int totalPages = ((totalRecords - 1) / pageSize) + 1; // C#
pageCnt = Fix((recordCnt + pageSize - 1) / pageSize) // ASP
[code]


其他

[code]
string str = String.Join(",", intList.ConvertAll<string>(new Converter<int, string>(m => m.ToString())).ToArray());
// C# String.Join 對 int,核心是 int List 轉 string List
// 看更簡單的(.NET 4 適用):
string str = String.Join<int>(",", intList);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.