nsstring

Read UTF8 character in specify position from a NSString

烂漫一生 提交于 2019-12-31 10:47:50
问题 NSString* str = @"1二3四5"; NSLog(@"%c",[str characterAtIndex:0]); NSLog(@"%c",[str characterAtIndex:1]); NSString - characterAtIndex works well on ASCII chars, but how could I get the UTF8 character at the index of 2? -- updated -- It seems unichar(16bits) can't represent all the UTF8 encoding strings(8bites to 32bites), so are there any method to get the char from NSString? 回答1: Unfortunately Dave's answer doesn't actually do what you want. The index supplied to

Read UTF8 character in specify position from a NSString

谁都会走 提交于 2019-12-31 10:47:11
问题 NSString* str = @"1二3四5"; NSLog(@"%c",[str characterAtIndex:0]); NSLog(@"%c",[str characterAtIndex:1]); NSString - characterAtIndex works well on ASCII chars, but how could I get the UTF8 character at the index of 2? -- updated -- It seems unichar(16bits) can't represent all the UTF8 encoding strings(8bites to 32bites), so are there any method to get the char from NSString? 回答1: Unfortunately Dave's answer doesn't actually do what you want. The index supplied to

How to use drawInRect:withAttributes: instead of drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment: in iOS 7

大兔子大兔子 提交于 2019-12-31 08:48:40
问题 This method is deprecated in iOS 7.0: drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment: Now use drawInRect:withAttributes: instead. I can't find the attributeName of fontSize and baselineAdjustment. Edit Thanks @Puneet answer. Actually, I mean if there doesn't have these key, how to implement this method in iOS 7? Like below method: + (CGSize)drawWithString:(NSString *)string atPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font fontSize:(CGFloat

How to get a single NSString character from an NSString

旧城冷巷雨未停 提交于 2019-12-31 08:30:38
问题 I want to get a character from somewhere inside an NSString. I want the result to be an NSString. This is the code I use to get a single character at index it: [[s substringToIndex:i] substringToIndex:1] Is there a better way to do it? 回答1: This will also retrieve a character at index i as an NSString, and you're only using an NSRange struct rather than an extra NSString. NSString * newString = [s substringWithRange:NSMakeRange(i, 1)]; 回答2: If you just want to get one character from an a

iOS: finding correct font size to fit in a UILabel depending on its size

会有一股神秘感。 提交于 2019-12-31 05:45:09
问题 I have a UILabel whose property text I would like to set paragraphs of text to using NSString . I have an array in which I store a sequence of characters that represent a text paragraph. The paragraph doesn't have to fit/included perfectly within this UILabel . If the paragraph doesn't end, I would move on to the next label. Let say if I had rect size of this UILabel 160 X 240, how could I be able to determine the correct font size in order to fill this string of the UILabel within nicely? Is

gethostbyname xcode issues

风格不统一 提交于 2019-12-31 05:19:47
问题 Hey guys, I'm new at this stuff, but I'm trying to use gethostname() to work using xcode and the ipad. I've tried a couple of things, but they all seem to freeze up. So when I just do: host = gethostbyname("website.com"); that works fine. I'd like to be able to change the website from within the program though. I've tried: const char *server = [Website_NSString UTF8String]; host = gethostbyname(server); const char *server = [Website_NSString cStringUsingEncoding:NSASCIIStringEncoding]; host =

Why does NSString sometimes work with the equal sign? [duplicate]

房东的猫 提交于 2019-12-31 04:43:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Understanding NSString comparison in Objective-C Was just reading up about equality vs identity and I realized that I've been using some equal signs when comparing strings in my objc code. The weird thing is that it actually works from times to times and I was wondering why. http://www.karlkraft.com/index.php/2008/01/07/equality-vs-identity/ I have two pieces of code, one work and one doesn't. WORKING. Here I

how to get String with two decimal places in iphone app

Deadly 提交于 2019-12-31 04:13:14
问题 I have app in which i have method which inserts comma in NSString in thousands values i also want to include decimall like if i enter now 1000 then it shows 1,000 using this method but i want 1,000.00 like this here is my method any idea how to fix this issue. - (NSString *)formatStringF:(NSString *)string { // Strip out the commas that may already be here: NSString *newString = [string stringByReplacingOccurrencesOfString:@"," withString:@""]; if ([newString length] == 0) { return nil; } //

Import csv data (SDK iphone)

流过昼夜 提交于 2019-12-31 04:06:08
问题 For the following code, I can read all the data in the string, and successfully get the data for plot. NSMutableArray *contentArray = [NSMutableArray array]; NSString *filePath = @"995,995,995,995,995,995,995,995,1000,997,995,994,992,993,992,989,988,987,990,993,989"; NSArray *myText = [filePath componentsSeparatedByString:@","]; NSInteger idx; for (idx = 0; idx < myText.count; idx++) { NSString *data =[myText objectAtIndex:idx]; NSLog(@"%@", data); id x = [NSNumber numberWithFloat:0+idx*0

Non-string key in NSDictionary object?

帅比萌擦擦* 提交于 2019-12-31 03:46:21
问题 I've parsed some JSON data using NSJSONSerialization from the Foundation framework - however, I'm getting a weird key for an NSDictionary group as follows "stop_times" = ( { "departure_time" = "5:48a"; "departure_timestamp" = 1355309284; "service_id" = 1; shape = "Scarborough RT To Kennedy Station"; } Any idea what the key "shape" might be? Is it a string? I didn't think so since it wasn't surrounded with double quotation marks. Thanks for your help in advance! 回答1: The description method of