NSLog () output function set format characters, nslog output function characters

Source: Internet
Author: User

NSLog () output function set format characters, nslog output function characters
The powerful functions of nslog () are not mentioned here. I transferred it from c #, and it is inevitable that there will be some strangers. In c #, format ("{0}", xx} is used for placeholder. The following describes the format characters in oc. * Additional symbols can be inserted between % and format.

  • L (letter): it can be used to output long integer integers before the format characters d, o, x, and u. It can also be used to output long floating point numbers before f, e, and g.
  • M (representing a positive integer): specifies the minimum width of the output data
  • N: For floating point numbers, it indicates that n decimal places are output; for strings, it indicates the number of characters in the block.
  • -: Indicates the output value to the left.
  • The following is an example:
  • The Code is as follows:
    Int a = 60; NSLog (@ "= % d =", a); NSLog (@ "= % 9d =", ); // output placeholder NSLog (@ "= %-8d =", a); // left alignment * Note: %-The placeholder must be written after the % symbol, NSLog (@ "=-% 8d --", a); // The NSLog (@ "= % o", a) is incorrect ); // octal double s = 3.141592653; NSLog (@ "= % f =", s ); // output float NSString * name = @ "hybriddb" in decimal form; // string is pointer type, such as c #, which is of special type (reference type) NSLog (@ "% @", name); // output string NSDate * date = [[NSDate alloc] init]; NSLog (@ "% @", date );
    --------- The result is as follows ---------- 00:11:49. 451367 Test [1713: 79881] = 60 = 00:11:49. 451597 Test [1713: 79881] = 60 = 00:11:49. 451623 Test [1713: 79881] = 60 = 00:11:49. 451635 Test [1713: 79881] =-60--2017-03-14 00:11:49. 451649 Test [1713: 79881] = 742017-03-14 00:11:49. 451669 Test [1713: 79881] = 3.141593 = 00:11:49. 451983 Test [1713: 79881] hybriddb 00:11:49. 457270 Test [1713: 79881] 16:11:49

Related Article

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.