Common methods of Objective-c NSString class

Source: Internet
Author: User

Tip: The previous more commonly used 1, the creation of String instance method:?-(Instancetype) Initwithformat: (nsstring*) format formatted to generate a string object? This method is more commonly used, powerful, and uses: [[NSString alloc]initwithformat:@ "I am student at%@ of technology?" @ "Guangdonguniversity"];-(instancetype)? Initwithstring: ( nsstring*) astring generate a String object based on the given string?-(Instancetype)? Initwithutf8string: (const char *) BytesUTF-8 the C string in encoded format generates a String object-(Instancetype) Initwithcharacters: (Constunichar *) characters???? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? Length: (nsuinteger) length generates a string object based on the given C string (no encoding) and string length? class Method:?? + (Instancetype) stringWithFormat: (nsstring*) format,... Format generated string? + (Instancetype) stringwithstring: (nsstring*) astring?+ (instancetype) stringwithcharacters: (const unichar* ) chars???? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? Length: (Nsuinteger) length?+ (instancetype) stringwithcstring: (const char *) cString???? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? Encoding: (nsstringencoding) enc?+ (instancetype) stringwithutf8string: (const char *) bytes?2, Common Properties @property (readonly) Nsuinteger?length? Get the length of the string? @property? (ReadOnly,?copy)? Nsstring?*uppercasestring: Convert lowercase letters in a string to uppercase? @property? (readonly,?copy)? Nsstring?*lowercasestring: Convert uppercase letters in a string to lowercase letters? @property? (readonly,?copy)? nsstring?*capitalizedstring; Convert the first letter of a word in a string to uppercase, the rest to lowercase? @property (readonly)? Double?doublevalue@property ( readonly)? Float?floatvalue @property (readonly)? Int?intvalue @property (readonly) Nsinteger?integervalue[email  protected] (readonly)? Long?long?longlongvalue@property (readonly)? Bool?boolvalue get the basic data type of the string? Call method: Str.uppercasestring;?? str.lowercasestring;? Str.capitalizedstring (instance name. Property name)?? 3, Common methods:?? -(nsstring*) Stringbyappendingformat: (NSString *) format, ... Add a formatted string after the string-(nsstring*) Substringfromindex: (Nsuinteger) Anindex intercept the substring (from the Anindex position character (inclusive) to the string? end)-(nsstring*) Substringtoindex: (nsuinteger) Anindex intercept substring (a string of Anindex characters from 0 positions)-(BOOL) containsstring: (nsstring*) STR Determines whether the string contains the STR string-(BOOL) Hasprefix: (NSString *) astring string contains astring string prefix-(bool) Hassuffix: (NSString *) Astring string contains astring string suffix-(BOOL) isequaltostring: (nsstring*) astring judgment string and ASTRis ing equal?-(Nsrange) rangeofstring: (NSString *) astring Find the range (starting position and length) of the astring string in the string that invokes the method-(nsstring*) Stringbyreplacingoccurrencesofstring: (nsstring*) target?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? Withstring: (nsstring*) replacement? Replace the substring target in the string with the replacement string-(nsstring*) Stringbyreplacingcharactersinrange: (nsrange) range??? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ??? Withstring: (NSString *) Replacement Replace the string in the range specified by range with the replacement string-(Nscomparisonresult) Compare: (NSString *) Astring comparison string and astring string-(NSString *) stringbyappendingstring: (NSString *) astring add string after string astring-(nsstring*) Substringwithrange: (nsrange) arange intercept substring (range determined by location and length in Arange) Nsrange with Nsmakerange (Nsuinteger Loc, Nsuinteger len) method obtained?-(Unichar) Characteratindex: (nsuinteger) index? Gets the character of the string index position (starting at 0)?? -(void) Getcharacters: (Unichar *) buffer stores the content character of the string into the buffer buffer?-(void) Getcharacters: (Unichar *) buffer???? ? ?? ? ?? ? ?? ?? Range: (nsrange) Arange the character of the range specified by rangestored in buffer?? Note: nsmutablestring (variable string) variable classes must be initialized first when defined?-(void) AppendFormat: (nsstring*) format,?... Appends a formatted string to a string-(void) appendString: (nsstring*) astring adds a string after the string astring?-(void) Deletecharactersinrange: (Nsrange) Arange Delete the string arange the specified range-(void) insertstring: (nsstring*) astring?????????????? ? ?? ? ?? Atindex: (nsuinteger) anindex? Insert string astring-(void) Replacecharactersinrange at anindex location: (nsrange) arange??? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? Withstring: (nsstring*) astring? Replace the string arange the specified range with astring-(void) setString: (nsstring*) astring set string to the given string astring?

Common methods for objective-c nsstring classes

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.