Commonly used one-sentence judgment code in various languages

Source: Internet
Author: User

Judge Chinese Characters

CopyCode The Code is as follows: if (system. Text. encoding. getencoding ("gb2312"). getbytes ("medium"). Length = 2) // C #
If (escape (STR). indexof ("% u") <0) // Javascript

Judge Number

Copy code The Code is as follows: Number. As (v) // ezj
Number. asint (v) // ezj determines the integer

Determine pure numbers

Copy code The Code is as follows: Number. aspurenumber (v) // ezj determines a pure number (a positive or negative number or a decimal point is not allowed)
System. Text. regularexpressions. RegEx. ismatch (STR, @ "^ \ D + $") // C #

Leap year

Copy code The Code is as follows: 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

Page number judgment

Copy code The Code is as follows: int totalpages = (totalrecords-1)/pagesize) + 1; // C #
Pagecnt = fix (recordcnt + pagesize-1)/pagesize) // ASP
[Code]

Others

[Code]
string STR = string. join (",", intlist. convertall (New converter (M => M. tostring ())). toarray ();
// C # string. join to int. The core is to convert int list to string list.
// It is simpler (. net 4):
string STR = string. join (",", intlist);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.