Objective-C specifications for formatting

Source: Internet
Author: User

Objective-C specifications for formatting

Objective-C format strings and C # are very different. Let's take a look at them.

InC #We can do this in a few simple examples:

1 // format the output string 2 string word = "world"; 3 string test = string. format ("hello {0}", word); 4 5 // Format the output number 6 int num = 100; 7 string myNum = string. format ("myNum = {0}", num); 8 9 // Format the output time 10 DateTime nowTime = DateTime. now; 11 string currentDate = string. format ("nowTime = {0}", nowTime );

InObjective-CWe need to perform the conversion in this way:

1 // format the string 2 NSString * world = @ "world"; 3 NSLog (@ "hello % @", world ); 4 5 // format an integer 6 int num = 2; 7 NSLog (@ "% d", num );

% @ Object
% D, % I Integer
% U, % z Unoperator integer
% F Floating Point/double-Character
% X, % X Hexadecimal integer
% O Octal integer
% Zu Size_t
% P Pointer
% E Floating Point/double-character (Scientific Computing)
% G Floating Point/double-Character
% S C string
%. * S Pascal string
% C Character
% C Unichar
% Lld 64-bit long integer (long)
% Llu 64-bit long integer
% Lf 64-bit dual-Character
% Hhd Boolean Type

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.