nsstring

数组排序

自闭症网瘾萝莉.ら 提交于 2019-12-19 05:23:28
1 #pragma mark 冒泡排序 2 - (void)userArrSort:(NSMutableArray *)userArr 3 { 4 int n = userArr.count; 5 int i,j; 6 NSDictionary *temp; 7 for(j=0;j<n-1;j++) 8 { 9 for(i=0;i<n-1-j;i++) 10 { 11 // NSDictionary*ssy = []; 12 if(((NSString *)[userArr[i] objectForKey:@"vlevel"]).intValue<((NSString *)[userArr[i+1] objectForKey:@"vlevel"]).intValue)//数组元素大小按升序排列 13 { 14 temp=userArr[i]; 15 userArr[i]=userArr[i+1]; 16 userArr[i+1]=temp; 17 } 18 } 19 } 20 for (int x = 0; x<userArr.count; x++) 21 { 22 if (1) { 23 // [userArr replaceObjectAtIndex:0 withObject:[userArr[i]]; 24 } 25 } 26 } 27 #pragma mark

Url minus query string in Objective-C

ε祈祈猫儿з 提交于 2019-12-19 05:03:16
问题 What's the best way to get an url minus its query string in Objective-C? An example: Input: http://www.example.com/folder/page.htm?param1=value1&param2=value2 Output: http://www.example.com/folder/page.htm Is there a NSURL method to do this that I'm missing? 回答1: There's no NSURL method I can see. You might try something like: NSURL *newURL = [[NSURL alloc] initWithScheme:[url scheme] host:[url host] path:[url path]]; Testing looks good: #import <Foundation/Foundation.h> int main(int argc,

received memory warning. level 1

二次信任 提交于 2019-12-19 04:55:20
问题 I am new to iPhone development. I am creating an application in which i need to create buttons and labels programmatically. So I am doing this in .h file @interface FirstQuizViewControlleriPad : UIViewController{ IBOutlet UIButton *startgame; UILabel *theQuestion; IBOutlet UIScrollView *scrollview; UILabel *Question; UILabel *Description; UIView *ContainerView; UILabel *Challengetext; UIImageView *img1; UIImageView *img2; UIImageView *background; IBOutlet UIButton *reviewbtn; UILabel *ans1;

NSString *string = @“someString” vs NSString *string = [[NSString alloc] initWithFormat@“%@”, string]

心不动则不痛 提交于 2019-12-19 04:16:05
问题 If I have a method - (void) myMethod:(NSString *)string { [Object anothermethodWithString:string]; } and I call [Object myMethod:@"this is a string with no alloc statement"] Do I need to do something like - (void) myMethod:(NSString *)string { NSString *string2 = [[NSString alloc] initWithFormat:@"%@", string]; [Object anothermethodWithString:string2]; [string2 release]; } instead of the way I had myMethod before? I have misbehaving code that seems to be caused by a string being auto-released

Regular Expression splitting up of NSString - iOS

南楼画角 提交于 2019-12-19 04:14:10
问题 Split String using Regular Expression in iOS I have solved this problem using loops, however would like a cleaner answer and I hope a reg exe guru can help me out. My original string could be like the following NSString *originalString = @"343 a mr smith needs this work"; NSString *originalStringVerTwo = @"345a mr jones needs this work as well"; NSString *originalStringVerThree = @"345 Mrs Someone"; I need to separate into 3 separate new strings: Number with or with a trailing "a" or "b",

oc _属性

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:56:23
// main.m // OC04_属性 // // Created by dllo on 15/7/17. // Copyright (c) 2015年 cml. All rights reserved. // #import <Foundation/Foundation.h> #import "Person.h" #import"Student.h" #import "Animal.h" int main(int argc,constchar * argv[]) { // Person *per =[[Person alloc] init]; //对象通过设置器对成员变量内容进行修该 // [per setName:@"你好"]; //对象通过访问器来进行取值 // NSLog(@"%@",[per name ]); //属性一共做了三件事 // 1.声明了设置器,setter和访问器getter // 2.实现了设置器和访问器 // 3.声明了一个成员变量,成员变量命名会在属性名前面加一个下划线 //具体的数据储存,还是成员变量来完成的,属性只不过帮助程序员完成一些繁琐的工作,简化代码 // Person *per =[[Person alloc] init]; // [per hobby]; //// [per buhao]; // Student *stu=[

iPhone - Comparing strings with a German umlaut

不羁岁月 提交于 2019-12-19 03:43:09
问题 I've few German strings (with umlauts like åä etc) in NSArray. For example consider a word like "gënder" is there in array. User enters "gen" in a text field. I can to check the words in string that matches the characters "gen". How can I compare the string by consider umlauts as english strings...? So in above example, when user enters "gen", it has to return "gënder". Is there any solution for this type of comparision? 回答1: Use the NSDiacriticInsensitiveSearch option of the various NSString

IOS之数据持久化

大兔子大兔子 提交于 2019-12-19 01:21:40
9.1 数据持久化概述 9.2 iOS应用程序目录结构 9.3 读写属性列表 9.4 对象归档 9.5 访问SQLite 9.1 数据持久化概述 iOS中可以有四种持久化数据的方式: 属性列表、对象归档、SQLite3和Core Data 9.2 iOS应用程序目录结构 iOS应用程序运行在Mac os模拟器时候,有一下临时目录模拟器3.1.3为例子: /Users/tony/Library/Application Support/iPhone Simulator/3.1.3/Applications IOS应用程序采用沙盒原理设计,ios每个应用程序都有自己的3个目录(Document,Library,tmp),互相之间不能访问。 Documents存放应用程序的数据。 Library目录下面还有Preferences和Caches目录,Preferences目录存放应用程序的使用偏好,Caches目录与Documents很相 似可以存放应用程序的数据。 tmp目录供应用程序存储临时文件。 9.3 读写属性列表 读取Documents目录下文件 可以获得应用程序的Documents文件夹。 NSArray* myPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,

NSString @“\” adding backslash character objective-c

送分小仙女□ 提交于 2019-12-18 21:11:27
问题 Does anyone know of an easy way to add a single backslash ( \ ) to a NSString in Objective-C? I am trying to have a NSString *temp = @"\/Date(100034234)\/" ; I am able to get a double backslash or no backslash, but unable to get a single backslash. Any help would be appreciated. Thanks 回答1: The string @"\\" is a single backslash, @"\\\\" is a double backslash 回答2: The strings and NSLog are working fine for me (iPhone SDK 3.1.2 and Xcode 3.2.1): NSLog(@"\\"); // output is one backslash NSLog(@

How to get number of days between two dates objective-c [duplicate]

别等时光非礼了梦想. 提交于 2019-12-18 17:33:10
问题 This question already has answers here : How can I compare two dates, return a number of days (4 answers) Objective C - calculating the number of days between two dates (6 answers) Closed 6 years ago . I'm trying to make a label that says how many days left till event. I want to calculate the difference between todays date and the events date. I'm using this code and its giving me -4600. It works fine till I use todays date. NSDateFormatter *f = [[NSDateFormatter alloc] init]; [f