10 Types of small questions

Source: Internet
Author: User

//

Main.m

Examination questions

//

Created by Zhong Jia Bo Zhong Group on 15/11/16.

Copyright (c) 2015 Com.sisp. All rights reserved.

//

#import <Foundation/Foundation.h>

#define NSLOG (FORMAT, ...) printf ("%s\n", [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string])

int main (int argc, const char * argv[]) {

@autoreleasepool {

/*

The world in the 1th string is replaced by the I Bookan wisdom

NSString *[email protected] "Hello World and Sunshine";

Open space for variable strings

Nsmutablestring *mustr=[[nsmutablestring Alloc]init];

To assign an immutable string to a mutable string

Mustr=[nsmutablestring STRINGWITHSTRING:STR1];

Replace

Nsrange rang=[mustr rangeofstring:@ "World"];

[Mustr Replacecharactersinrange:rang withstring:@ "I Bookan wisdom"];

NSLog (@ "%@", mustr);

*/

/*

The 2nd string is summed, output as a string, and the output length

NSString *[email protected] "999";

NSString *[email Protected] "888";

Connection string

NSString *newstr=[[nsstring alloc]initwithformat:@ "%@%@", STR2,STR3];

NSLog (@ "%@", newstr);

Calculating string Lengths

Nsuinteger len = [newstr length];

NSLog (@ "%ld", Len);

*/

/*

Question 3rd Comparing string sizes

NSString *[email protected] "ABC";

NSString *[email protected] "ABc";

Comparison of two string sizes

Nscomparisonresult result= [STR4 COMPARE:STR5];

Judging condition nsorderedascending represents a small size before ascending

if (result==nsorderedascending) {

NSLog (@ "STR4<STR5");

Nsordereddescending represents descending before large after small

}else if (result==nsordereddescending) {

NSLog (@ "STR4>STR5");

}else{

NSLog (@ "STR4=STR5");

}

*/

/*

The 4th question intercepts Android and outputs

NSString *[email protected] "iphoneandroid";

All characters starting at the specified position (and including the specified position) start at 0

NSString *NEWSTR2=[STR6 Substringfromindex:6];

NSLog (@ "%@", NEWSTR2);

*/

/*

Question 5th creates an OC string in C and outputs it. Two methods are used.

C Language String

Char *s= "Zhangsanfeng";

int a=9;

printf ("%s", s);

Convert to OC string

NSString *str = [NSString stringwithformat:@ "%d", a];

NSLog (@ "%@", str);

OC string to C language string

NSString *[email protected] "Yangyang";

Convert OC to String

const char *strstring=[string utf8string];

NSLog (@ "%s", strstring);

*/

/*

All a in the 6th string is replaced by A;

NSString *[email protected] "whatareyou";

NSString *NEWSTR=[STR7 stringbyreplacingoccurrencesofstring:@ "A" withstring:@ "a"];

NSLog (@ "%@", newstr);

*/

/*

Question 7th determine if the string starts with HTTP

NSString *[email protected] "http://www.sina.com.cn";

BOOL result = [str8 hasprefix:@ "http"];

if (result==1) {

NSLog (@ "starts with http");

}else{

NSLog (@ "not beginning with http");

}

*/

/*

The 8th question is to intercept the string within admin and 123.

NSString *[email protected] "http://localhost:8099/test/user=admin&pwd=123";

Nsrange rang;

Nsrange rang1;

rang.location=32;

rang.length=5;

rang1.location=42;

rang1.length=3;

NSString *NEWSTR3=[STR9 Substringwithrange:rang];

NSString *NEWSTR4=[STR9 Substringwithrange:rang1];

NSLog (@ "%@", NEWSTR3);

NSLog (@ "%@", NEWSTR4);

*/

/*

The 9th inscription added Telephone:iphone iphone5 modified to "Telephone:iphone iphone4 iphone5 iphone6";

NSString *[email protected] "Telephone:iphone iphone5";

Assign a variable string to an immutable string, assign a value

Nsmutablestring *mustr=[[nsmutablestring Alloc]init];

Mustr=[nsmutablestring Stringwithstring:str10];

Inserting a string in a fixed position

[Mustr insertstring:@ "iphone4" atindex:17];

Inserts a string at the end

[Mustr appendstring:@ "Iphone6"];

NSLog (@ "%@", mustr);

*/

/*

Sort 10th question

*/

Nsarray *[email protected][@ "string One", @ "string", @ "string 1", @ "String 2", @ "string 02";

Nsarray *sortarr=[arr sortedarrayusingselector: @selector (compare:)];

for (id str in sortarr) {

NSLog (@ "%@", str);

}

}

return 0;

}

10 Types of small questions

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.