nsstring

Transliterate/transpose the characters in the NSString

梦想的初衷 提交于 2019-12-02 21:04:44
I want to transliterate a cyrillic string to it's closest latin equivalent. E.g. "матрешка" => "matreshka", "водка" => "vodka". So ideally I want some ready to use method on the NSString or somewhere else that already knows everything about the alphabets and can do the conversation. But if such functionality doesn't exist in the iOS APIs then I will be totally happy with something like ruby's tr method that just replaces the characters in a string using a simple mapping specified as a parameter. "баба".tr('абвгд', 'abvgd') ksh Either try CFStringTransform function of CFMutableString with

Converting NSDecimalNumber to NSString

…衆ロ難τιáo~ 提交于 2019-12-02 20:43:55
I'm retrieving a key from an object that looks like this: po obj { TypeID = 3; TypeName = Asset; } The key value is being retrieved like this: NSString *typeId = (NSString*)[obj objectForKey:@"TypeID"]; Rather than typeId being an NSString, it is an NSDecimalNumber. Why is that? How do I convert it to an NSString? You need to use the stringWithFormat function: NSString *typeId = [NSString stringWithFormat:@"%@", [obj objectForKey:@"TypeID"]]; or stringValue : NSString *typeId = [[obj objectForKey:@"TypeID"] stringValue]; This should work: NSString *typeId = [[obj objectForKey:@"TypeID"]

Convert NSTimeInterval to NSString in iPhone?

荒凉一梦 提交于 2019-12-02 20:18:05
How to covert the NSTimeInterval to NSString? I have NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; I have to give "today" as input as NSString. NSTimeInterval is just a double type so you can convert it to string using +stringWithFormat: method NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; NSString *intervalString = [NSString stringWithFormat:@"%f", today]; 来源: https://stackoverflow.com/questions/4278129/convert-nstimeinterval-to-nsstring-in-iphone

passing the value from one class to other class

泪湿孤枕 提交于 2019-12-02 20:00:39
问题 I am facing the problem in displaying the value of string of AddNotesViewController Class , in the Label of the DetailsOfPeopleViewController . All i want to do is whatever we entered in the UITextView of 1 class,should display in the UILabel of another class. In file AddNotesViewController.h UITextView *txtView; @property(nonatomic,retain)IBOutlet UITextView *txtView; in file AddNotesViewController.m @synthesize txtView; After this when i click on the tab bar item "save" then it should save

Objective C: convert a NSMutableString in NSString

假如想象 提交于 2019-12-02 19:54:53
I have an NSMutableString, how can I convert it to an NSString? Either via: NSString *immutableString = [NSString stringWithString:yourMutableString]; or via: NSString *immutableString = [[yourMutableString copy] autorelease]; //Note that calling [foo copy] on a mutable object of which there exists an immutable variant //such as NSMutableString, NSMutableArray, NSMutableDictionary from the Foundation framework //is expected to return an immutable copy. For a mutable copy call [foo mutableCopy] instead. Being a subclass of NSString however you can just cast it to an NSString NSString

Do loops and convenience methods cause memory peaks with ARC?

偶尔善良 提交于 2019-12-02 19:33:30
I'm working with ARC and seeing some strange behavior when modifying strings in a loop. In my situation, I'm looping using NSXMLParser delegate callbacks, but I see the same exact behavior and symptoms using a demo project and sample code which simply modifies some NSString objects. You can download the demo project from GitHub , just uncomment one of the four method calls in the main view controller's viewDidLoad method to test the different behaviors. For simplicity's sake, here's a simple loop which I've stuck into an empty single-view application. I pasted this code directly into the

compare special characters like À with regular A

南笙酒味 提交于 2019-12-02 19:31:15
问题 In some languages there are letters like À , I saw that for table view sections the native iOS put À under the same section as A . I want to do the same thing, I'm building my sections by comparing the first letter, so I need that À will be equal to A. I tried using localizedCompare but still I didn't got that those two are equal. Is there a way to to this kind of compare? or to normalised À so it will be A ? 回答1: Don't convert or transform as per the other answers. First, try -[NSString

stringWithFormat vs. initWithFormat on NSString

你说的曾经没有我的故事 提交于 2019-12-02 19:14:53
I am wondering what differences such as disadvantages and/or advantages there are to declaring an NSString this way: NSString *noInit = [NSString stringWithFormat:@"lolcatz %d", i]; as opposed to: NSString *withInit = [[NSString alloc] initWithFormat:@"Hai %d", i]; What was the motivation of putting stringWithFormat instead of just having the initWithFormat way of initializing the string? stringWithFormat: returns an autoreleased string; initWithFormat: returns a string that must be released by the caller. The former is a so-called "convenience" method that is useful for short-lived strings,

Inserting Unicode Hyphen-minus into String Causes Error

送分小仙女□ 提交于 2019-12-02 19:14:48
问题 I am trying to insert a unicode hyphen-minus character into a text string. I am seeing an "Invalid universal character" error with the following: u+002D (hyphen-minus) [textViewContent insertString:@"\u002D" atIndex:cursorPosition.location]; However, these work fine: u+2212 (minus) [textViewContent insertString:@"\u2212" atIndex:cursorPosition.location]; u+2010 (hyphen) [textViewContent insertString:@"\u2010" atIndex:cursorPosition.location]; I've poked at several of the existing Unicode

How to convert byte array to NSString

丶灬走出姿态 提交于 2019-12-02 18:36:34
I am reading data from a TCP/IP stream and am successfully receiving a byte array from the pre-existing server. I am now trying to find a way to convert that array to an NSString . I have found several examples, but am having a hard time getting my desired results. NSData *data=[[NSMutableData alloc] init]; uint8_t buffer[1024]; unsigned int len=0; len=[(NSInputStream *)stream read:buffer maxLength:1024]; if(len>0){ [data appendBytes:&buffer length:len]; //BYTE ARRAY OBTAINED OK!! /////////////////////////////////////////////////////// //METHOD #1 - Yields 'nil' NSString *string = [[NSString