OC string intercept convert variable string case

Source: Internet
Author: User
Tags hex code

////main.m//string////Created by MAC on 15/12/9.//copyright©2015 year MAC. All rights reserved.//#import<Foundation/Foundation.h>#import<string.h>intMainintargcConst Char*argv[]) {@autoreleasepool {nsstring*name =@"Xiaoren"; intAge = -; NSString*name1 = [NSString stringWithFormat:@"name=%@ age=%d", Name,age]; NSLog (@"%@", name1); Nsuinteger Len=[name1 length]; NSLog (@"%lu", Len); Charc = [name1 Characteratindex:4];//get the 4th index characterNSLog (@"%c", c);  for(intI=0; i<len; i++) {NSLog (@"%c", [name1 characteratindex:i]); } NSData*date = [name1 datausingencoding:nsutf8stringencoding];//convert to 16-binary charactersNSLog (@"%@", date); NSString*name3 = [[NSString alloc]initwithdata:date encoding:nsutf8stringencoding];//Convert hex code to stringNSLog (@"%@", Name3); //Write a fileNSString *str =@"Hello World"; NSString*path =@"/users/mac/desktop/test.txt"; BOOL result= [str writetofile:path atomically:yes encoding:nsutf8stringencoding Error:nil];//Write FileNSLog (@"result=%d", result); NSString*newstring =[NSString Stringwithcontentsoffile:path encoding:nsutf8stringencoding Error:nil]; NSLog (@"%@", newstring); NSLog (@"%@", name1); NSLog (@"%@", [name1 Substringfromindex:5]);//intercept all characters from the fifth postNSLog (@"%@", [name1 Substringtoindex:5]);//intercept the first five charactersNsrange range = Nsmakerange (4,8);//RangeNSLog (@"%@", [name1 Substringwithrange:range]);//intercept strings by range//Character ConversionsNSString *age2 =@" -";//0 If it is not of type intNSString *name2 =@"3.14"; NSString*name5 =@"false"; intA =[Age2 Intvalue]; floatb =[name2 Floatvalue]; NSLog (@"%d", a); NSLog (@"%f", B); BOOL cc=[Name5 Boolvalue]; NSLog (@"%d", CC); //String Case ConversionNSString *STR3 =@"Hello World"; NSLog (@"%@", [STR3 uppercasestring]);//convert to uppercase output HELLO worldNSLog (@"%@", [STR3 lowercasestring]);//Convert to lowercase output Hello worldNSLog (@"%@", [STR3 capitalizedstring]);//Convert to first letter uppercase output Hello world//string comparisonNSString *STR6 =@"a"; NSString*STR7 =@"b"; Nscomparisonresult R=[STR6 COMPARE:STR7]; NSLog (@"%ld",(Long) r);//0 means equal//variable String//variable strings are inherited NSString, and method properties in NSString can be used in nsmutablestring//1. Generally initializes a class with a static method so that no management of memory is the direct access to the method through the class name does not require Alloc//direct access through the class name method does not require management memorynsmutablestring *strr1 = [[nsmutablestring alloc]initwithcapacity:5]; //direct access through the class name method does not require management memorynsmutablestring *MSTR2 = [nsmutablestring stringwithcapacity:Ten]; //Direct Assignment variable string C methodnsmutablestring *MSTR3 = [nsmutablestring stringwithstring:@"Xiaowang"]; //2. Append the length of the string beyond the initialization length will be added automatically[MStr2 appendString:@"Xiaoren"]; [MStr2 appendString:@"20222"]; NSLog (@"%@", MSTR2); //3. Delete charactersNsrange len1 = Nsmakerange (2,4);        [MStr2 Deletecharactersinrange:len1]; NSLog (@"%@", MSTR2); //4. Inserting characters[MStr2 insertstring:@"yy"Atindex:4]; NSLog (@"%@", MSTR2); //5. Replace all replace strings[MStr2 setString:@"Tihuan"]; NSLog (@"%@", MSTR2); }    return 0;}

OC string intercept convert variable string case

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.