Objective-C nsstring cannot be modified

Source: Internet
Author: User

Objective-C uses nsstring to operate strings. nsstring is called a non-modifiable string because the content and length of a string cannot be modified when you create a string using nsstring.

1. Create a string

 
Nsstring * STR = @ "I Am a string ";

2. format the string

 
Nsstring * name = @ "Zhang"; nsstring * log = [nsstring stringwithformat: @ "I am '% @'", name]; nslog (@ "str: % @", log );

Format the output symbol:

 
% @ Object % d, % I integer % u unsigned integer % F floating point/double character % x, % x binary 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 no character 64-bit long integer % lf 64-bit double character % E is a real number, calculated by scientific notation

3. Use one character string to initialize another character string:

 
Nsstring * STR = @ "I Am a string"; nsstring * str1 = [nsstring stringwithstring: Str];

4. String comparison and determination

 
-(Bool) isequaltostring :( nsstring *) string;-(bool) hasprefix: (nsstring *) string;-(bool) hassuffix: (nsstring *) string;

5. Numerical Conversion

 
-(INT) intvalue;-(double) doublevalue;-(nsinteger) integervalue;-(float) floatvalue;

6. case-sensitive Conversion

 
-(Nsstring *) lowercasestring; // convert it to an unwritten string-(nsstring *) uppercasestring; // convert it to an uppercase string

7. String Truncation

 
-(Nsstring *) substringfromindex: I; // returns the substring (nsstring *) substringtoindex: I from the beginning to the end; // returns the string starting from string to I-(nsstring *) substringwidthrange: range; // returns the string in the returned range.

8. Obtain the string length.

 
-(Unsigned INT) length;

9. convert a char * string to an nsstring

Char * string = "I Am a string"; nsstring * nstring = [[nsstring alloc] initwithuf8string: String];

10. Obtain the nsstring as a char * string.

 
Nsstring * STR = @ "I Am a string"; char * CSTR = [STR utf8string];

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.