nsstring

How do I split a string with special characters into a NSMutableArray

青春壹個敷衍的年華 提交于 2020-01-02 05:14:12
问题 I'am trying to seperate a string with danish characters into a NSMutableArray. But something is not working. :( My code: NSString *danishString = @"æøå"; NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[danishString length]]; for (int i=0; i < [danishString length]; i++) { NSString *ichar = [NSString stringWithFormat:@"%c", [danishString characterAtIndex:i ]]; [characters addObject:ichar]; } If I do at NSLog on the danishString it works (returns æøå); But if I do a NSLog

Remove part of an NSString

强颜欢笑 提交于 2020-01-02 05:06:24
问题 I have an NSString as follows: <img alt="996453912" src="http://d2gg0uigdtw9zz.cloudfront.net/large/996453912.jpg" /><a href="http://www.dealcatcher.com/shop4tech-coupons">Shop4Tech Coupons</a> I only need the first part (before the <a href part), and I cannot figure out how to remove the second part. I have tried a ton, but it has not worked. 回答1: Use something like: NSRange rangeOfSubstring = [string rangeOfString:@"<a href"]; if(rangeOfSubstring.location == NSNotFound) { // error condition

Appending unichar to NSMutableString

二次信任 提交于 2020-01-02 02:24:07
问题 How do you append a unichar character to NSMutableString ? unichar c = 'T'; NSMutableString *s = [NSMutableString stringWithString:@"MyString"]; // want s to become "MyStringT" https://discussions.apple.com/thread/1679290 suggests: [s appendString:[NSString stringWithCharacters:&c length:1]]; Looks too long / complicated... 回答1: Use [NSString appendFormat:], so for above: [s appendFormat:@"%C", c]; Enjoy! 来源: https://stackoverflow.com/questions/29357205/appending-unichar-to-nsmutablestring

Split string by delimiter

淺唱寂寞╮ 提交于 2020-01-02 01:17:04
问题 I really can't find this answer... I have multiline NSString called myString in XCode, and it is a HTML code. I need to navigate the string by lines, for example: myString = @"<html>" "<body>" "<head><title>My Page</title>"; How can I access line per line? like: LineOne = myString.Lines[0]; LineTwo = myString.Lines[1]; How can I do something like that in XCode??? I need something like the Memo component in Delphi... 回答1: The most html strings will have (mostly invisible) newline delimiters

Superscripted ordinal suffix in NSString

吃可爱长大的小学妹 提交于 2020-01-02 00:16:09
问题 Is there a way in NSString to output the st, nd, and rd but in a superscripted format? Any known unicode perhaps? 回答1: There doesn't seem to be any Unicode characters for this, but it's easy enough to make an NSAttributedString that will do the trick: NSDictionary * superscriptAttrs = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:NSSuperscriptAttributeName]; NSAttributedString * st = [[NSAttributedString alloc] initWithString:@"st" attributes:superscriptAttrs];

IOS中对象的归档

回眸只為那壹抹淺笑 提交于 2020-01-01 21:56:09
ios提供了两个类 NSKeyedArichiver NSKeyedUnarchiver对自定义对象进行归档 和解档操作 归档常见方法 - (void)encodeObject:(id)objv forKey:(NSString *)key; - (void)encodeConditionalObject:(id)objv forKey:(NSString *)key; - (void)encodeBool:(BOOL)boolv forKey:(NSString *)key; - (void)encodeInt:(int)intv forKey:(NSString *)key; // native int - (void)encodeInt32:(int32_t)intv forKey:(NSString *)key; - (void)encodeInt64:(int64_t)intv forKey:(NSString *)key; - (void)encodeFloat:(float)realv forKey:(NSString *)key; - (void)encodeDouble:(double)realv forKey:(NSString *)key; - (void)encodeBytes:(const uint8_t *)bytesp length:

IOS --- 对象归档

我的未来我决定 提交于 2020-01-01 21:55:50
原文:http://blog.sina.com.cn/s/blog_7124765801015imx.html IOS提供的数据持久化方式有:SQLite、CoreData、属性列表、NSUserDefault、对象归档。 这里来简单介绍下对象归档: 对象归档是将对象归档以文件的形式保存到磁盘中(也称为序列化,持久化),使用的时候读取该文件的保存路径读取文件的内容(也称为接档,反序列化), (对象归档的文件是保密的,在磁盘上无法查看文件中的内容,而属性列表是明文的,可以查看)。 对象归档有两种方式:1:对foundation中对象进行归档 2:自定义对象归档 1、简单对象归档 使用两个类:NSKeyedArichiver、NSKeyedUnarchiver NSString *homeDirectory = NSHomeDirectory(); //获取根目录 NSString homePath = [homeDirectory stringByAppendingPathComponent:@"自定义文件名,如test.archiver"]; NSArray *array = @[@"abc", @"123", @12]; Bool flag = [NSKeyedArichiver archiveRootObject:array toFile:homePath]; if(flag)

iOS archive(归档)的总结

你离开我真会死。 提交于 2020-01-01 21:54:46
iOS 归档的记录 归档是一种很常用的文件储存方法,几乎任何类型的对象都能够被归档储存(实际上是一种文件保存的形式),浏览网上的一些资料后,并结合自己的一些经验,总结成此文。 一、使用archiveRootObject进行简单的归档 使用NSKeyedArichiver进行归档、NSKeyedUnarchiver进行接档,这种方式会在写入、读出数据之前对数据进行序列化、反序列化操作。 归档: NSString *homeDictionary = NSHomeDirectory(); //获取根目录 NSString *homePath = [homeDictionary stringByAppendingPathComponent:@ "atany.archiver" ]; //添加储存的文件名 BOOL flag = [NSKeyedArchiver archiveRootObject:@”归档” toFile:homePath]; //归档一个字符串 这种方式可以对字符串、数字等进行归档,当然也可以对NSArray与NSDictionary进行归档。返回值Flag标志着是否归档成功,YES为成功,NO为失败。 接档: [NSKeyedUnarchiver unarchiveObjectWithFile:homePath] 使用NSKeyedUnarchiver进行接档(反序列化

ios的 对象归档

邮差的信 提交于 2020-01-01 21:53:43
IOS提供的数据持久化方式有:SQLite、CoreData、属性列表、NSUserDefault、对象归档。 这里来简单介绍下对象归档: 对象归档是将对象归档以文件的形式保存到磁盘中(也称为序列化,持久化),使用的时候读取该文件的保存路径读取文件的内容(也称为接档,反序列化), (对象归档的文件是保密的,在磁盘上无法查看文件中的内容,而属性列表是明文的,可以查看)。 对象归档有两种方式:1:对foundation中对象进行归档 2:自定义对象归档 1、简单对象归档 使用两个类:NSKeyedArichiver、NSKeyedUnarchiver NSString *homeDirectory = NSHomeDirectory(); //获取根目录 NSString homePath = [homeDirectory stringByAppendingPathComponent:@"自定义文件名,如test.archiver"]; NSArray *array = @[@"abc", @"123", @12]; Bool flag = [NSKeyedArichiver archiveRootObject:array toFile:homePath]; if(flag) { NSLog(@"归档成功!"); } 读取归档文件的内容: NSArray *array =

iOS base64 加密解密 通用类

二次信任 提交于 2020-01-01 20:03:28
本文转载自: https://www.cnblogs.com/ygm900/archive/2013/05/15/3079278.html 作者:ygm900 转载请注明该声明。 在使用过程中,直接将被类引入到项目中即可,不需要其它辅助类。 使用示例: 将此通用类的头文件引入到目标类后,直接使用类名进行调用即可。 NSString *str = [NSString stringWithFormat: @" YWE= " ]; NSString *str1 = [NSString stringWithFormat: @" aa " ]; NSLog( @" resultStr========%@ " ,[CommonFunc textFromBase64String:str]); //使用类名进行调用 NSLog( @" resultStr=========%@ " ,[CommonFunc base64StringFromText:str1]); //使用类名进行调用 源码下载: 在项目中遇到字符串的base64编解码,分享一下工具类: CommonFunc.h // // CommonFunc.h // PRJ_base64 // // Created by wangzhipeng on 12-11-29. // Copyright (c) 2012年 com.comsoft.