nsstring

Separating NSString into NSArray, but allowing quotes to group words

一笑奈何 提交于 2019-12-10 03:56:25
问题 I have a search string, where people can use quotes to group phrases together, and mix this with individual keywords. For example, a string like this: "Something amazing" rooster I'd like to separate that into an NSArray, so that it would have Something amazing (without quotes) as one element, and rooster as the other. Neither componentsSeparatedByString nor componentsSeparatedByCharactersInSet seem to fit the bill. Is there an easy way to do this, or should I just code it up myself? 回答1: You

What's the equivalent “sizeWithFont: ” method for the Mac?

眉间皱痕 提交于 2019-12-10 03:43:51
问题 I'm familiar with sizeWithFont: for the iPhone. Now I'm trying to build an app for the Mac and need something like that, but I don't know how to do it :/ Here's why I need it: I've got a panel that displays some text, and I want to size it so that it just fits the content (a NSTextView ). How would you do it? 回答1: Take a look at NSString's sizeWithAttributes: . You'll have to create a dictionary of attributes; take a look at Apple's documentation for that. 来源: https://stackoverflow.com

Converting NSString to Date

依然范特西╮ 提交于 2019-12-10 03:24:24
问题 I have two strings: date1 = 3-3-2011; and i want to convert in to 3-March-2011 and display it in label. NSString *myString = 3-3-2011; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"d-MM-YYYY"]; NSDate *yourDate = [dateFormatter dateFromString:myString]; //now format this date to whatever you need… [dateFormatter setDateFormat:@"d-MMM-YYYY"]; NSString *resultString = [dateFormatter stringFromDate:yourDate]; [dateFormatter release]; but yourdate

In Objective-C, how to print out N spaces? (using stringWithCharacters)

这一生的挚爱 提交于 2019-12-10 01:52:36
问题 The following is tried to print out N number of spaces (or 12 in the example): NSLog(@"hello%@world", [NSString stringWithCharacters:" " length:12]); const unichar arrayChars[] = {' '}; NSLog(@"hello%@world", [NSString stringWithCharacters:arrayChars length:12]); const unichar oneChar = ' '; NSLog(@"hello%@world", [NSString stringWithCharacters:&oneChar length:12]); But they all print out weird things such as hello ÔÅÓñüÔÅ®Óñü®ÓüÅ®ÓñüÔ®ÓüÔÅ®world ... I thought a "char array" is the same as a

Confused by NSStringDrawingOptions item meaning

廉价感情. 提交于 2019-12-10 01:52:24
问题 iOS7 and later, we can use - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context to calculate the string size, but I'm confused with the comments on NSStringDrawingOptions enum. NSStringDrawingUsesLineFragmentOrigin It means specified origin is the line fragment origin, not the base line origin. But what mean of line fragment origin and baseline origin. Just like the WWDC 2013 Session 220

How to convert a string to float? [duplicate]

£可爱£侵袭症+ 提交于 2019-12-10 01:21:16
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Convert string to float in Objective-C I'd like to convert a string to a float. /* dict is an NSDictionary to load Preferences */ NSString *str = [dict objectForKey:@"key"]; This is where I got. Now I'd like to convert the string value (in this case @"32.0f" ) in a float, where it could be processed by my application. How can I do this? 回答1: CGFloat strFloat = (CGFloat)[str floatValue]; 回答2: Just pass the

IOS开发网络篇之──ASIHTTPRequest下载示例(支持断点续传)

天涯浪子 提交于 2019-12-09 23:07:51
在工程中,我们会常常遇到需要下载的程序,比如下载在线音乐、下载图片等等,今天我将介绍一下利用ASIHTTPRequest的下载示例,支持断点续传,利用ASIHTTPRequest下载以及断点续传的原理在我的博客:http://blog.csdn.net/pjk1129/article/details/6575588中有具体的介绍,今天重点介绍如何实现,废话少说,开始正文: 一、创建网络请求队列 首先,创建网络请求队列,如下: ASINetworkQueue *que = [[ASINetworkQueue alloc] init]; self.netWorkQueue = que; [que release]; [self.netWorkQueue reset]; [self.netWorkQueue setShowAccurateProgress:YES]; [self.netWorkQueue go]; 二、创建存放路径 // 初始化 Documents 路径 NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; // 初始化临时文件路径 NSString *folderPath = [path stringByAppendingPathComponent:@"temp

converting an NSString with accented characters to a CString

一曲冷凌霜 提交于 2019-12-09 18:27:25
问题 I have an NSString with a value of Jose (an accent on the e). I try to convert it to a C string as follows: char str [[myAccentStr length] + 1]; [myAccentStr getCString:str maxLength:[myAccentStr length] + 1 encoding:NSUTF32StringEncoding]; but str ends up being an empty string. What gives? I tried UTF8 and UTF16 too. It gets passed to another function later on and when that funcsion calls lstrlen on it, the size comes out as zero. 回答1: The docs for NSString getCString:maxLength:encoding says

OC 第二次检查命名规范思考与学习

微笑、不失礼 提交于 2019-12-09 16:43:17
紧接着上篇,每次看也不要求全部都会,哪怕每次学到一个技术点也算是赚了: 任务:对自己项目的方法命名进行优化。 这篇主题:Naming Methods (命名方法) 第一: ******对于表示对象执行的操作的方法,以_动词_开头名称: ****** (void) select TabViewItem:(NSTabViewItem *)tabViewItem 第二: ******不要使用Do或does作为名字的一部分,因为这些助动词很少增加意思。另外,不要在动词前使用副词或形容词。 ****** 第三: 如果方法返回接收者的属性,则以该属性命名方法。 除非间接地返回一个或多个值,否则没有必要使用“get”。 - (NSSize)cellSize; Right. - (NSSize)calcCellSize; Wrong. - (NSSize)getCellSize; Wrong. 第四,在所有参数之前使用关键字: - (void)sendAction:(SEL)aSelector toObject:(id)anObject forAllCells:(BOOL)flag; Right. - (void)sendAction:(SEL)aSelector :(id)anObject :(BOOL)flag; Wrong. 第五,在论证之前造一个词来描述这个论证: - (id

if NSString does not equal function?

让人想犯罪 __ 提交于 2019-12-09 16:38:57
问题 I have searched all over the place for this, including apple's docs on NSString (maybe I didn't see?) but I am trying to find a method in xCode for checking wether a NSString does not equal to something. Much like if (myNSSting = @"text" {... except specifically I want to check if it does not equal to 'text'. 回答1: if(![myNSString isEqualToString:@"text"]) 回答2: For case insensitive compare we can handle by: if( [@"Some String" caseInsensitiveCompare:@"some string"] == NSOrderedSame ) { //