nsstring

comma separated thousand NSString stringWithFormat

萝らか妹 提交于 2019-12-30 00:51:07
问题 Is it possible to display 1000.99 as 1,000.99 using [NSString stringWithFormat:@"£%0.2f", 1000.99] Please guide me if I am not on the right track to achieve this? 回答1: See NSNumberFormatter. It can handle all your numeric formatting needs and do so in an automatically localized fashion, when used correctly (since currencies around the world are often written with different punctuation & formatting). In particular, check out the number formatting guide linked to at the top of the class

Objective-C语法快速参考(收藏)

为君一笑 提交于 2019-12-29 20:17:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 大部分有一点其他平台开发基础的初学者看到XCode,第一感想是磨拳擦掌,看到Interface Builder之后,第一感想是跃跃欲试,而看到Objective-C的语法,第一感想就变成就望而却步了。好吧,我是在说我自己。 如 果你和我一样,对苹果相关的开发:Mac OS X或是iPhone有兴趣,但是第一时间看到Objective-C就会头疼并伴有发烧症状的话,疗效比较好的快速治疗方法是阅读本文。大概花二十分钟左 右,而且绝不无聊的时间,你就会对Objective-C有那么一点点了解,至少读读例子不会那么头疼了。 不过假定你要有那么一点点c++、c#或是java的基础,至少能看到c++、c#或是java的源码,能够大致明白说得是什么。 这篇文章不是一篇科技文章,希望你也不要把它当做科技文章来读。文章非常不严谨,但是我相信你能看得懂。 一、XCode、Objective-C、Cocoa说的是几样东西? 答案:三样东西。 XCode: 你可以把它看成是一个开发环境,就好像 Visual Studio 或者 Netbeans 或者 SharpDevelop 一样的玩意。你可以将 Interface Builder 认为是 Visual Studio 中用来画界面的那部分功能单独提出来的程序。 Objective-C

How to determine if the first character of a NSString is a letter

北战南征 提交于 2019-12-29 18:43:08
问题 In my app i need to know if the first character of a string is a letter or not Im getting first character of the string like this NSString *codeString; NSString *firstLetter = [codeString substringFromIndex:1]; I can know it by comparing with a, b, c, .**. if([firstLetter isEqualToString "a"] || ([firstLetter isEqualToString "A"] || ([firstLetter isEqualToString "b"] ......) But is there any other method to know? I need to display different colors for letters and symbols. How can i achieve it

iOS 时间和时间戳之间转化

若如初见. 提交于 2019-12-29 16:09:24
以毫秒为整数值的时间戳转换 时间戳转化为时间NSDate - (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // 格式化时间 NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"]; // 毫秒值转化为秒 NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0]; NSString* dateString = [formatter stringFromDate:date]; return dateString; } 时间转化为时间戳 // 当前时间 NSDate* date = [NSDate

iOS开发-清理缓存功能的实现

做~自己de王妃 提交于 2019-12-29 12:06:54
移动应用在处理网络资源时,一般都会做离线缓存处理,其中以图片缓存最为典型,其中很流行的离线缓存框架为SDWebImage。 但是,离线缓存会占用手机存储空间,所以缓存清理功能基本成为资讯、购物、阅读类app的标配功能。 今天介绍的离线缓存功能的实现,主要分为缓存文件大小的获取、删除缓存文件的实现。 获取缓存文件的大小 由于缓存文件存在沙箱中,我们可以通过NSFileManager API来实现对缓存文件大小的计算。 计算单个文件大小 +(float)fileSizeAtPath:(NSString *)path{ NSFileManager *fileManager=[NSFileManager defaultManager]; if([fileManager fileExistsAtPath:path]){ long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize; return size/1024.0/1024.0; } return 0; } 计算目录大小 +(float)folderSizeAtPath:(NSString *)path{ NSFileManager *fileManager=[NSFileManager defaultManager]; float

BOOL to NSString

这一生的挚爱 提交于 2019-12-29 10:52:44
问题 If I have a method that returns a BOOL , how do I cast that to an NSString so I can print it out in console? For example, I tried doing this, which isn't working: NSLog(@"Is Kind of NSString:", ([thing isKindOfClass:[NSString class]]) ? @"YES" : @"NO"); But I really want to actually turn the return value into an NSString. I know it's a primitive data type, so I can't call methods on it. Do I have to create a string separately and then use the Bool as a parameter in a method on NSString? 回答1:

Detecting if NSString contains chinese characters

六月ゝ 毕业季﹏ 提交于 2019-12-29 09:10:33
问题 I have an UISearchBar , and I want my data to be sorted by pinYin if the user inputs English, and sorted by the characters themselves when the user inputs Chinese characters. Is there something like if (searchText isKindofClass: UTF-8String) to detect if an NSString contains Chinese characters? 回答1: You can use a NSRegularExpression to search for "character families" : https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference

Objective-C: Find consonants in string

余生长醉 提交于 2019-12-29 09:03:37
问题 I have a string that contains words with consonants and vowels. How can I extract only consonants from the string? NSString *str = @"consonants."; Result must be: cnsnnts 回答1: You could make a character set with all the vowels (@"aeiouy") + (id)characterSetWithCharactersInString:(NSString *)aString then use the - (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set method. EDIT: This will only remove vowels at the beginning and end of the string as pointed out in the other post,

Do NSString objects need to be alloc and init?

走远了吗. 提交于 2019-12-29 08:33:11
问题 Noob question: I'm currently under the impression that when you want to create an object, you need to alloc and init that object. However, I've seen seen several sample codes where an NSString object is declared, yet I see no alloc or init messages following... A very simple example: NSString *myString = @"Hello World"; NSLog(@"%@" , myString); Can someone explain why this is so? 回答1: Declaring a variable does not require releasing any memory. Instantiating objects does. And you only

Special Characters in NSString from HTML

匆匆过客 提交于 2019-12-29 06:58:47
问题 I'm fetching data from an XML source and parsing through it with tbxml. Everything is working fine until I get to a latin letter like the "é" it will display as: Code: é I don't see a proper method of NSString to do the conversion. Any ideas? 回答1: This seems like a pretty common problem. Check out HTML character decoding in Objective-C / Cocoa Touch 回答2: You can use a regex. A regex is a solution to, and cause of, all problems! :) The example below uses, at least as of this writing, the