nsstring

Split NSString multiple times on the same separator

倾然丶 夕夏残阳落幕 提交于 2019-11-26 16:02:50
问题 I am currently receiving a string like this: @"Sam|26,Hannah|22,Adam|30,Carlie|32,Jan|54" And I am splitting it like this: testArray = [[NSArray alloc] init]; NSString *testString = [[NSString alloc] initWithFormat:@"Sam|26,Hannah|22,Adam|30,Carlie|32,Jan|54,Steve|56,Matty|24,Bill|30,Rob|30,Jason|33,Mark|22,Stuart|54,Kevin|30"]; testArray = [testString componentsSeparatedByString:@","]; dict = [NSMutableDictionary dictionary]; for (NSString *s in testArray) { testArray2 = [s

Converting HTML text into plain text using Objective-C

杀马特。学长 韩版系。学妹 提交于 2019-11-26 15:38:21
问题 I have huge NSString with HTML text inside. The length of this string is more then 3.500.000 characters. How can i convert this HTML text to NSString with plain text inside. I was using scanner , but it works too slowly. Any idea ? 回答1: It depends what iOS version you are targeting. Since iOS7 there is a built-in method that will not only strip the HTML tags, but also put the formatting to the string: Xcode 9/Swift 4 if let htmlStringData = htmlString.data(using: .utf8), let attributedString

Is it possible to include a quotation mark as part of an nsstring?

守給你的承諾、 提交于 2019-11-26 15:24:39
I have a label that displays inches. I would like to display the number with the inch symbol (") or quotation mark. Can I do this with an nsstring? Thanks! Jeff Kelley Sure, you just need to escape the quotation mark. NSString *someString = @"This is a quotation mark: \""; NSLog(@"%@", someString ); Output: This is a quotation mark: " You can use Double Quote Escape Sequence here. You need to escape it using a backslash : NSString *str = @"Hello \"World\""; NSLog(@"Output : %@",str); Output : Hello "World" There are some other Escape Sequences also. Take a look at it : \b Backspace \f Form

Encrypted NSData to NSString in obj-c?

喜夏-厌秋 提交于 2019-11-26 15:22:44
问题 I have an iPhone app which encrypts an inputted NSString using CCCrypt (AES256) and a plaintext key. The string and key are given to the encryption method which returns an NSData object. Requesting [data description] where 'data' is the encrypted string data gives an NSString like: "<0b368353 a707e7de 3eee5992 ee69827e e3603dc2 b0dbbc0b 861ca87d f39ce72a>" but when I try to convert that to an NSString, I get "(null)". I need to return an NSString to the user, which can be used to decrypt back

Converting escaped UTF8 characters back to their original form

旧时模样 提交于 2019-11-26 15:21:08
I'm trying to read strings from an array that's coming from a plist and print those strings. The strings in the array contain escaped UTF8 characters - for example "Nuša Florjančič" becomes "Nu\u0161a Florjan\u010di\u010d" when read from the plist. There is no way to change the content of the plist, but my program needs to display the names properly. The strange thing is that Objective-C seems to do this automatically when I'm hardcoding the string. However, if I get the string from the plist nothing happens at all. To give you an example, here's some code: NSString *name1 = @"Nu\u0161a

sizeWithFont method is deprecated. boundingRectWithSize returns an unexpected value

雨燕双飞 提交于 2019-11-26 15:14:56
问题 In iOS7, sizeWithFont is deprecated, so I am using boundingRectWithSize (which returns a CGRect value). My code: UIFont *fontText = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16]; // you can use your font. CGSize maximumLabelSize = CGSizeMake(310, 9999); CGRect textRect = [myString boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:fontText} context:nil]; expectedLabelSize = CGSizeMake(textRect.size.width,

Convert an NSURL to an NSString

你说的曾经没有我的故事 提交于 2019-11-26 15:05:54
问题 I have an app where the user can choose an image either from the built-in app images or from the iphone photo library. I use an object Occasion that has an NSString property to save the imagePath . Now in the case of the built-in app images I do get the file name as an NSString an save in the [occasion imagePath] . But in the 2nd case where the user picks an image form the photo library I get an NSURL which I want to convert to an NSString to be able to save it in [occasion imagePath ]. Is it

UILabel - string as text and links

核能气质少年 提交于 2019-11-26 14:59:04
I have a UILabel whose text I am getting from a server. Some of the text is to be identified as links, and on touching those links some action should be performed. e.g. NSString *str = @"My phone number is 645-345-2345 and my address is xyz "; This is the complete text for UILabel . I have only one UILabel for displaying this text (Text is dynamic. I just gave an example.). On clicking these links I need to perform actions like navigating to some different screen or make a call. I know that I can display such text with help of OHAttributedLabel . And the links can be displayed as follows :

NSString 转化 NSURL NSURL 转化 NSString

こ雲淡風輕ζ 提交于 2019-11-26 14:55:37
1 NSString 转化 NSURL 2 SString *urlString=[ @" http://www.google.com/search?client=safari&rls=en&q=搜索&ie=UTF-8&oe=UTF-8 " stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 1 NSURL 转化 NSString 2 NSURL *url= [NSURL URLWithString:urlString]; 3 NSString *s=[[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 转载于:https://www.cnblogs.com/liwentao1091/p/4626706.html 来源: https://blog.csdn.net/weixin_30410119/article/details/98903184

IOS 关键字self,super,copy, retain, assign , readonly

早过忘川 提交于 2019-11-26 14:43:35
#synthesize关键字: 根据@property设置,自动生成成员变量相应的存取方法,从而可以使用点操作符来方便的存取该成员变量 。 @implementation 关键字,表明类的实现 @end 结束 self 关键字 :类似于java中的this,是隐藏参数,指向当前调用方法的类。 super 关键字 :调用父类的方法。 self = [superinit] 这里不是判断self与[superinit]是否相等,而是判断是否可以成功初始化。[super init]:父类初始化成功的话,通过=给self,这样self成为一个非空对象,整个来说即非false(非NO)。 #import 告诉预处理器,将头文件的内容包含到本文件中. OC 中的import 能保证头文件只会被包含一次 .@interface关键字:声明一个Student类。 @end 结束声明. 冒号:表示继承 后面跟的是父类. NSObject是大多数对象都会用到的内存管理,和初始化框架,以及反射和类型操作. 相 当于Object。 NS是NextSTEP缩写,表示这个函数来自Cocoa工具包。 声明全局变量 , 与C中一样。 property关键字:设置成员变量的属性(有读/写,赋值assign,retain,copy ,以及对多线程的支持nonatomic)。 声明一个方法,格式是 –(返回值)