nsstring

How to convert NSArray into NSString

Deadly 提交于 2019-11-27 15:13:13
问题 How to convert NSArray into NSString in objective-c? 回答1: Bearing in mind that you don't say what's in the NSArray, you can do this: NSArray *arr = [NSArray arrayWithObjects: @"foo", @"bar", @"baz"]; [arr componentsJoinedByString: @","] 回答2: Aternatively to Frank's method, which works pretty well, you could also do NSString *myArrayString = [array description]; The default implementation of description on NSArray will print out the contents in a neatly formatted fashion. 回答3: This is how I

Detect Unicode characters in NSString on iPhone

微笑、不失礼 提交于 2019-11-27 15:09:35
问题 I am working on an SMS application for the iPhone. I need to detect if the user has entered any unicode characters inside the NSString they wish to send. I need to do this is because unicode characters take up more space in the message, and also because I need to convert them into their hexadecimal equivalents. So my question is how do I detect the presence of a unicode character in an NSString (which I read from a UITextView). Also, how do I then convert those characters into their UCS‐2

String won't url encode in iOS

天大地大妈咪最大 提交于 2019-11-27 14:48:47
I'm seriously having a brain fart here, but I can't figure out why this isn't encoding for the life of me. Been searching all over, and I can't even get the code samples to encode. Any ideas? NSString *searchString = @"waffl&es"; NSString *encodedSearchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *urlString = [NSString stringWithFormat:@"http://en.wikipedia.org/?search=%@", encodedSearchString]; NSURL *url = [NSURL URLWithString:urlString]; For future reference, this is what I found to work (i.e. encode everything properly) + (NSString*

Combine Two String in different Language RTL & LTR

北城余情 提交于 2019-11-27 14:40:59
I have two text, one in Hebrew language and one in English. In first text I have date that is in Hebrew. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew [dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"]; NSDate *date = [dateFormatter dateFromString:model.startDate]; NSLog(@"%@", date); [dateFormatter setDateFormat:@"EEEE,dd.MM.yyyy"]; dateFormatter.locale = hebrew; NSString *strDate = [dateFormatter stringFromDate:date]; and start Date is : יום שישי,19.08.2016 in NString object strDate

NSString instance reports its class as NSCFString

吃可爱长大的小学妹 提交于 2019-11-27 14:20:22
My objective here is really simple -- I'm trying to set an NSString to some test data, then return the class, which should be NSString . Here's my code: NSString* stringer = [NSString stringWithFormat: @"Test"]; NSLog(@"%@", [stringer class]); The log says that the class is NSCFString , not NSString . What's going on here? NSString is really a container class for different types of string objects. Generally an NSString constructor does return an object that is actually of type NSCFString, which is a thin wrapper around the Core Foundation CFString struct. NSString is a class cluster , along

Adding a drop shadow to NSString text in a drawRect: method without using UILabel

半腔热情 提交于 2019-11-27 13:38:46
问题 I'd like to add a drop shadow to text drawn using the iOS supplied NSString (UIStringDrawing) category method: - (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize lineBreakMode:(UILineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment; Clearly, there's no drop shadow option. Yes, one could use a UILabel here and get drop shadow properties to set, but that

NSString question - rangeOfString method

心已入冬 提交于 2019-11-27 13:30:16
问题 I am having an issue that I can't figure out. I'm trying to run the rangeOfString method on a string, and I'm not sure how to determine if the string was not found. For example: NSRange range = [@"abc" rangeOfString:@"d" options:NSCaseInsensitiveSearch range:NSMakeRange(0,3)]; Clearly, "d" is not contained in the string "abc." I'd like to be able to do this: if(the range is empty since "d" is not in "abc") //do something What is the code for this? Thanks!! 回答1: From the documentation of

iPhone开发之深入浅出 (1) — ARC是什么

烂漫一生 提交于 2019-11-27 13:05:33
ARC是什么 ARC是iOS 5推出的新功能,全称叫 ARC(Automatic Reference Counting)。简单地说,就是代码中自动加入了retain/release,原先需要手动添加的用来处理内存管理的引用计数的代码可以自动地由编译器完成了。 该机能在 iOS 5/ Mac OS X 10.7 开始导入,利用 Xcode4.2 可以使用该机能。简单地理解ARC,就是通过指定的语法,让编译器(LLVM 3.0)在编译代码时,自动生成实例的引用计数管理部分代码。有一点,ARC并不是GC,它只是一种代码静态分析(Static Analyzer)工具。 变化点 通过一小段代码,我们看看使用ARC前后的变化点。 @interface NonARCObject : NSObject { NSString *name; } -(id)initWithName:(NSString *)name; @end @implementation NonARCObject -(id)initWithName:(NSString *)newName { self = [super init]; if (self) { name = [newName retain]; } return self; } -(void)dealloc { [name release]; [Super dealloc

NSTask NSPipe - objective c command line help

守給你的承諾、 提交于 2019-11-27 12:55:24
Here is my code: task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:@"/applications/jarvis/brain/"]; [task setLaunchPath:@"/applications/jarvis/brain/server.sh"]; NSPipe * out = [NSPipe pipe]; [task setStandardOutput:out]; [task launch]; [task waitUntilExit]; [task release]; NSFileHandle * read = [out fileHandleForReading]; NSData * dataRead = [read readDataToEndOfFile]; NSString * stringRead = [[[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding] autorelease]; So I'm trying to replicate this: cd /applications/jarvis/brain/ ./server.sh but using NSTask in objective-c

Check if an NSString is just made out of spaces

放肆的年华 提交于 2019-11-27 12:54:20
问题 I want to check if a particular string is just made up of spaces. It could be any number of spaces, including zero. What is the best way to determine that? 回答1: NSString *str = @" "; NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet]; if ([[str stringByTrimmingCharactersInSet: set] length] == 0) { // String contains only whitespace. } 回答2: Try stripping it of spaces and comparing it to @"": NSString *probablyEmpty = [myString stringByTrimmingCharactersInSet:[NSCharacterSet