Small white Study Development (IOS) OC_ basic data types converted to strings (2015-08-12)

Source: Internet
Author: User

//

Main.m

// basic data type converted to string

//

Created by admin on 15/8/13.

Copyright (c) years admin. All rights reserved.

//


#import <Foundation/Foundation.h>


int Main (int argc,const Char * argv[]) {

@autoreleasepool {

basic Data type:(int float,double char)

1. INT--NSString

int a = ten;

nsstring *str1 = [nsstringstringwithformat:@ "%d", a];

NSLog (@ "str1 =%@", str1);

2. Float--NSString

float f = 3.6;

nsstring *str2 = [nsstringstringwithformat:@ "%.1f", F];

NSLog (@ "str2 =%@", str2);


3. Double--NSString

double d = 9.887;

nsstring *str3 = [nsstringstringwithformat:@ "%.4f", d];

NSLog (@ "STR3 =%@", STR3);


4. CHAR--NSString

char c = ' s ';

nsstring *STR4 = [nsstringstringwithformat:@ "%c", c];

NSLog (@ "STR4 =%@", STR4);

use stringWithFormat to stitch the above string

nsstring *STR5 = [nsstringstringwithformat:@ "%d%.1f%.4f%c", A,f,d,c];

NSLog (@ "STR5 =%@", STR5);

// Note: when converting a string to a data type, make sure the data is correct

5. NSString to int

nsstring *STR6 = @ "+";

int i = [STR6 intvalue];

NSLog (@ "i =%d", i);

6. NSString-Folat

nsstring *str7 = @ "5.6";

float j = [Str7 floatvalue];

NSLog (@ "j =%f", J);

7. NSString--Double

nsstring *str8 = @ "13.1416";

double k = [str8 doublevalue];

NSLog (@ "k =%f", K);

//8. Converts letters in a string to uppercase

nsstring *STR9 = @ "ABCDEFG";

nsstring *str10 = [STR9 uppercasestring];

NSLog (@ "str10 =%@", Str10);

//9. Convert letters in a string to lowercase

nsstring *str11 = @ "HappyBirthday";

nsstring *str12 = [Str11 lowercasestring];

NSLog (@ "str12 =%@", Str12);

10. capitalize the first letter

nsstring *str13 = @ "Dormitoy";

nsstring *str14 = [Str13 capitalizedstring];

NSLog (@ "str14 =%@", Str14);

}

return 0;

}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Small white Study Development (IOS) OC_ basic data types converted to strings (2015-08-12)

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.