nsstring

iOS: NSString when uploaded to parse.com shows blank

泄露秘密 提交于 2019-12-14 04:23:11
问题 I have taken an NSString from one class to another to be saved on parse.com I have a quiz view controller where a user enters a question in a UITextView and then they press next to go to the select friends view controller where they select a user and then send the question over parse. quiz.h @property (nonatomic,strong) IBOutlet UITextView *textField; @property (nonatomic, strong) NSString *text; quiz.m - (void)viewDidLoad { [super viewDidLoad]; UITextView *textView = [[UITextView alloc] init

Pass NSString between two DetailViewController

我只是一个虾纸丫 提交于 2019-12-14 04:10:42
问题 MasterViewController.m #import "DetailViewController.h" - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"DetailViewControllerSeque"]) { DetailViewController *detailView = [segue destinationViewController]; NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; theList = [app.listArray objectAtIndex:indexPath.row]; detailView.theList = theList; // String to pass to DetailViewController detailView.string2pass = @"this is

Lifespan of NSString cStringUsingEncoding return value

瘦欲@ 提交于 2019-12-14 03:59:33
问题 I have an NSTextField and get its contents like so NSString *s = [textField stringValue] Now I want to convert this NSString to a string that my platform-independent C code can handle. Thus I'm doing: const char *cstr = [s cStringUsingEncoding:NSISOLatin1StringEncoding]; What I don't understand now is how long this "cstr" pointer stays valid. Apple docs for cStringUsingEncoding say: The returned C string is guaranteed to be valid only until either the receiver is freed, or until the current

NSString to NSNumber ignores initial zeros

泪湿孤枕 提交于 2019-12-14 03:44:33
问题 I am converting NSString to NSNumber . But the problem is that if NSString starts with zeros then converting it to NSNumber ignores the initial zeros. I know initial zeros doesn't mean anything but I want to keep initial zeros because it's phonenumber in my case. here is my code: NSLog(@"test1: %@",tempPhoneNumber); NSNumberFormatter *formatter=[[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *tempPnoneNumberNumber=[formatter

split NSString given a number of characters in objective C [closed]

↘锁芯ラ 提交于 2019-12-14 03:29:40
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have two strings that are taken as input from a textfield in my application. I know that they are both 4 characters in length. Is there some way I can "halve" those strings, and create two strings per original

iOS: NSString loses URL, (null) is shown

白昼怎懂夜的黑 提交于 2019-12-14 02:29:21
问题 This is my Code so far: NSString *listedImageURL = listedProduct.image; NSLog(@"URL: %@", listedImageURL); This Code works fine and NSLog shows me the correct URL. But when I try the following Code, NSLog shows up (null): NSString *listedImageURL = listedProduct.image; NSURL *imageURL = [NSURL URLWithString:listedImageURL]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData]; What am I doing wrong?? 回答1: I believe that relower is on

Trouble spotting memory leak cStringUsingEncoding

一个人想着一个人 提交于 2019-12-14 02:13:48
问题 Hey, I am trying to convert NSString to a C string using cStringUsingEncoding but I have a memory leak. My understanding is that cStringUsingEncoding returns a pointer to a character array that is only guaranteed to exist for the duration of the NSString object. As such you should copy its contents to another string. Here's where my problem lies... I have a function that accepts an NSString and turns it into a C-string copy. Just for testing I ran 1,000 iterations of the following method (to

Check if NSString hasPrefix that is contained in NSArray

不想你离开。 提交于 2019-12-14 02:05:16
问题 I have this if statement to check if a URL starts with a prefix: NSString *baseUrl = @"http://example.com/"; NSString *currentURL = @"http://example.com/confirm"; if( [currentURL hasPrefix:[baseUrl stringByAppendingString:@"confirm"]] ){ // True, so do something... } I would like to modify the hasPrefix part of my if statement so that it returns true if currentUrl is appended by ANY of the values in my NSArray shown here: NSArray *pages = [NSArray arrayWithObjects:@"confirm",@"products",nil];

Get a long value from an NSString

那年仲夏 提交于 2019-12-14 01:54:21
问题 I need to get a long value from an NSString . For example, I have this: NSString *test = @"5437128"; and I need : long myLong = 5437128; How I can get this long value from the NSString ? Thank you, it will help me! 回答1: Use the NSScanner like in the following code: unsigned x; [[NSScanner scannerWithString: s2] scanHexInt: &x]; when typing the scanHexInt stop at scan and see yourself which one you need - there are many possibilities to get values from strings.... You might want to use

extract specific string in NSString

五迷三道 提交于 2019-12-14 00:42:01
问题 i think it is a simple question but i dont know how to solve it. i have a NSString that containes html content. i want to extract some tags. NSString *string=@"test some text <img src='http://www.xyz.com/a.jpg' > blah blah <a href='asdfg'>aaaa</a> bbbb cccc"; i want to take img & "a" tag into new string. then i will display it in UIWebView. how can i parse it? 回答1: The best way is to write a partial tag parser. This is not very difficult. Another option is to simply find the position of src='