nsstring

align text using drawInRect:withAttributes:

巧了我就是萌 提交于 2019-11-28 03:23:15
In the iOS 5 version of my app I had: [self.text drawInRect: stringRect withFont: [UIFont fontWithName: @"Courier" size: kCellFontSize] lineBreakMode: NSLineBreakByTruncatingTail alignment: NSTextAlignmentRight]; I'm upgrading for iOS 7. The above method is deprecated. I'm now using drawInRect:withAttributes: . The attributes parameter is an NSDictionary object. I can get drawInRect:withAttributes: to work for the former font parameter using this: UIFont *font = [UIFont fontWithName: @"Courier" size: kCellFontSize]; NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: font,

Make a two-digit string from a single-digit integer

狂风中的少年 提交于 2019-11-28 02:58:39
How can I have a two-digit integer in a a string, even if the integer is less than 10? [NSString stringWithFormat:@"%d", 1] //should be @"01" I believe that the stringWithFormat specifiers are the standard IEEE printf specifiers . Have you tried [NSString stringWithFormat:@"%02d", 1]; Use the format string %02d . This specifies to format an integer with a minimum field-width of 2 characters and to pad the formatted values with 0 to meet that width. See man fprintf for all the gory details of format specifiers. If you are formatting numbers for presentation to the user, though, you should

How do I convert NSInteger to NSString datatype?

房东的猫 提交于 2019-11-28 02:54:30
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]]; 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]; Obj-C way =): NSString *inStr = [@(month) stringValue]; MadNik Modern Objective-C An NSInteger has the method stringValue that can be used even with a literal NSString *integerAsString1 = [@12 stringValue]; NSInteger number = 13;

Capitalize or change case of an NSString in Objective-C

独自空忆成欢 提交于 2019-11-28 02:51:59
I was wondering how to capitalize a string found in an object in an NSMutableArray . An NSArray contains the string 'April' at index 2. I want this to be changed to 'APRIL' . Is there something simple like this? viewNoteDateMonth.text = [[displayDate objectAtIndex:2] capitalized]; Here ya go: viewNoteDateMonth.text = [[displayDate objectAtIndex:2] uppercaseString]; Btw: "april" is lowercase ➔ [NSString lowercaseString] "APRIL" is UPPERCASE ➔ [NSString uppercaseString] "April May" is Capitalized/Word Caps ➔ [NSString capitalizedString] "April may" is Sentence caps ➔ (method missing; see

Replacing in NSString with wildcards / regular expressions - cocoa

為{幸葍}努か 提交于 2019-11-28 02:28:34
NSString *x=@"\"/Sagar\' and \'Samir\' "; Now, I want to remove characters between these. \" / \' Intended output x = (should have) @"and \'Samir\'" So, Ms word give some options in find & replace, using wild card characters. ( just giving example ) Is it possible in cocoa? I'll assume you're looking for a solution in general -- not for this particular string. You'll want to learn about regular expressions . For regular expression support in Objective-C check out RegexKitLite . It provides category methods on NSString that support various regex matching and substitution. You could also use

What is a NSPathStore2? [closed]

▼魔方 西西 提交于 2019-11-28 02:26:47
问题 All that I know is this: Its private Its created somehow cause of strings trying to do Path related things I mean, if they are private and still my app is telling me that NSPathStore2 is interfering, I need to know why . I just want to understand why a release of NSPathStore2 is making my app crash. 回答1: NSPathStore2 is a subclass of NSString , used when creating strings that contain paths. For all intents and purposes, you should treat it as a NSString . 来源: https://stackoverflow.com

what is actual difference between NSString and NSMutableString in objective C with the help of example? [duplicate]

戏子无情 提交于 2019-11-28 02:23:50
问题 This question already has an answer here: What is the purpose of having both NSMutableString and NSString? 4 answers What is the difference between NSString and NSMutableString? [duplicate] 4 answers what is actual difference between NSString and NSMutable String in Objective-C? I have searched a lot but not getting any answer..I understand that NSString is Immutable object and NSMutableString is Mutable object but I want to understand the difference between them with the help of an example.

Why does isEqualToString not work for NSString?

时光毁灭记忆、已成空白 提交于 2019-11-28 02:19:35
问题 I am trying to code the login process for an iPhone app in XCode. The problem is with the NSString serverOutput below. When I print it using printf(serverOutput.UTF8String); it prints 'Yes' to the console. However when I compare serverOutput to "Yes" it doesn't work. Any help would be appreciated. Here's my code: - (IBAction) loginButton: (id) sender { // TODO: spawn a login thread indicator.hidden = FALSE; [indicator startAnimating]; NSString *post =[NSString stringWithFormat:@"username=%@

Add backslash to String in Objective-c

你离开我真会死。 提交于 2019-11-28 02:13:23
I have a problem identical to this problem here . I even want to encode the same infromation as him (it's a date/time for asp.net)... When ever I try to add a backslash i get two backslashes since I used \. Everyone in the thread above has claimed that this is a problem with NSLog and that NSString does treat \\ as a \ . I have checked this further by using a packet sniffer to examine the packets I'm sending to the webserver and I can confirm that it is transmitting a double backslash instead of a single backslash. Does anyone know how to add a backslash to a NSString? The strings and NSLog

Check if two NSStrings are similar

偶尔善良 提交于 2019-11-28 02:04:05
I present a tricky question that I am not sure how to approach. So, I have formulated a plist containing dictionaries which contain two objects: The Country Name The Plug Size Of The Country There are only 210 countries/facts though. And, I have enabled to search through a list of many many countries, in which there might be a fact or not. But here is my problem, I am using a web service called Geonames and the user can use a search bar display controller to search for countries, and these plist country names paired with plug sizes are actually from a Wikipedia article. Now, the country naming