nsstring

determine the maximum number of characters a UILabel can take

我只是一个虾纸丫 提交于 2019-12-17 21:05:23
问题 Given a UILabel and a NSString, how do I determine how much of the string can fit inside the UILabel? I am using Xcode-5 and iOS-7. I have been trying to see what I can extract from the thread Calculating UILabel Text Size but I am not getting anywhere with the responses there. 回答1: Well, what I did here works though there may be another, more efficient (yet less straight-forward) way. What I did was just calculate the size of the rect needed for the text, see if it fits in the label's frame,

Name for %@ %d in an NSString

只谈情不闲聊 提交于 2019-12-17 20:25:54
问题 What are these called in Objective C? @"%@" @"%d" @"%i" 回答1: They are called format specifiers, could also be called 'placeholders in a string for the variables that will follow'. https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html 回答2: They are NSString literal s. More specifically, they look they are being used as formatting strings for printf style functions. 回答3: I believe that they are called 'format placeholders', as suggested

Sort characters in NSString into alphabetical order

▼魔方 西西 提交于 2019-12-17 19:49:19
问题 I'm trying to re-arrange words into alphabetical order. For example, tomato would become amoott, or stack would become ackst. I've found some methods to do this in C with char arrays, but I'm having issues getting that to work within the confines of the NSString object. Is there an easier way to do it within the NSString object itself? 回答1: I think separate the string to an array of string(each string in the array contains only one char from the original string). Then sort the array will be

Format a date from a string

跟風遠走 提交于 2019-12-17 19:31:15
问题 I'm trying to format a date from a string into another format. For example: 2012-05-29 23:55:52 into 29/05 *newline* 2010 . I just don't get the logics behind NSDate and NSDateFormatter, I think.. Any help will be appreciated. Thanks :) 回答1: You will need to create an NSDateFormatter, and then set it's dateFormat to match the first date you have, eg: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; That will set your date

UILabel, UIFont and UTF-8 Triangle

妖精的绣舞 提交于 2019-12-17 19:00:41
问题 I'd like to use "BLACK RIGHT-POINTING TRIANGLE" (U+25B6) as a part of my UILabel 's text. The label uses the system font ( UIFont 's systemFontOfSize: ). The problem is that my triangle is rendered as a fancy image, not a "black right-pointing triangle". Is it possible to see the plain version? 回答1: Based on: Unicode characters being drawn differently in iOS5 iOS 6 supports Unicode 6.1's variation selector , in this case \U0000FE0E . To answer my own question: @"\U000025B6" // a fancy

How can we write " in nsstring?

微笑、不失礼 提交于 2019-12-17 18:52:35
问题 I have to initialize string as "Rose" including Quotation Mark. How to write " in our string? 回答1: Escape the double quote with \ NSString *yourString = @"\"Rose\""; 回答2: Use the escape character: \ NSString *r = @"\"Rose\""; You can find additional information about Escape character and String literal. 回答3: Escape it with a backslash: @"\"Rose\"" 回答4: Escape the quotation marks. Example: NSString *str = @"\"Rose\""; 回答5: NSString *yourString = @"\"Rose\""; 回答6: In swift 5, you can write with

How do I convert NSInteger to NSString datatype?

五迷三道 提交于 2019-12-17 17:24:39
问题 How does one convert NSInteger to the NSString datatype? I tried the following, where month is an NSInteger : NSString *inStr = [NSString stringWithFormat:@"%d", [month intValue]]; 回答1: NSIntegers are not objects, you cast them to long , in order to match the current 64-bit architectures' definition: NSString *inStr = [NSString stringWithFormat: @"%ld", (long)month]; 回答2: Obj-C way =): NSString *inStr = [@(month) stringValue]; 回答3: Modern Objective-C An NSInteger has the method stringValue

Concatenate int and string

假如想象 提交于 2019-12-17 16:53:34
问题 How can I concatenate an int (e.g: 4 ) and a string (e.g: @"/12" ) for printing? I'm okay with casting the int it to an NSString format, but I don't know how I can add @"/12" after the int's value. 回答1: I don't get your question, but I think you mean something like this: ...[NSString stringWithFormat:@"%d/12", intValue] 来源: https://stackoverflow.com/questions/5884367/concatenate-int-and-string

NSString method to percent escape '&' for URL

前提是你 提交于 2019-12-17 16:44:27
问题 Which NSString encoding method will percent escape the ampersand ( & ) character correctly into %26 ? stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding gets the spaces (%20) and other baddies but ignores ampersands!?! 回答1: Ampersands won't be processed by that method because they're legal characters in a URL. You should probably pre-process particularly problematic pieces, piecemeal, prior to this call. 回答2: Here is a nice solution to this problem taken from Bagonca blog to url

How to check if NSString is numeric or not [duplicate]

对着背影说爱祢 提交于 2019-12-17 16:32:59
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: iphone how to check that a string is numeric only I have one NSString, then i want check the string is number or not. I mean NSString *val = @"5555" ; if(val isNumber ){ return true; }else{ retun false; } How can I do this in Objective C? 回答1: Use [NSNumberFormatter numberFromString: s] . It returns nil if the specified string is non-numeric. You can configure the NSNumberFormatter to define "numeric" for your