iOS development nsstring conversion to int and float and string concatenation

Source: Internet
Author: User

One, nsstring and int and float of the mutual conversion

NSString *tempa = @ "123";

NSString *TEMPB = @ "456";

1. String concatenationNSString *newstring = [NSString stringwithformat:@ "%@%@", TEMPA,TEMPB];

 2. Character Representable int
  int intstring = [newstring intvalue];

3.int to character
  NSString *stringint = [NSString stringwithformat:@ "%d", intstring];

4. Character representable float float floatstring = [newstring floatvalue];5.float Turn character

  NSString *stringfloat = [NSString stringwithformat:@ "%f", intstring];

Second, string splicing

NSString *string;//result string nsstring* string1, string2;//existing string, string1 and string2 need to be connected//method One: string = [NSString in Itwithformat :@ "%@,%@" , string1, string2 ];Method Two: string = [string1 stringbyappendingstring:string2]; Method Three: String = [string stringByAppendingFormat:@ "%@,%@" ,string1, string2];

 

iOS development nsstring conversion to int and float and string concatenation

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.