nsstring

convert NSArray of NSString(s) to NSArray of NSMutableString(s)

和自甴很熟 提交于 2019-12-04 06:10:00
问题 How to do that without having to "scroll" the entire given array with a "for" loop? 回答1: Since nobody seems to agree with my comment that this is a duplicate of Better way to convert NSArray of NSNumbers to array of NSStrings, here's the same answer again: NSArray * arrayOfMutableStrings = [arrayOfStrings valueForKey:@"mutableCopy"]; From the docs: valueForKey: Returns an array containing the results of invoking valueForKey: using key on each of the array's objects. - (id)valueForKey:

Paste String Data from UIPastboard

牧云@^-^@ 提交于 2019-12-04 05:54:58
问题 I made an IOS app that using OCR to scan barcodes and copies the data to UserDefaults.standard.value(forKey: "barcodeId") as! String from a receipt. I'm trying to auto-populate the data taken from I've managed to pass the data to the element ID, But the data scanned using OCR doesn't populate the correct value. Below information from the console. NOTE: I've obscured the URL, Since It's a private URL. Optional(8.906010283900207e+17) is what I need to pass to the element ID on the webbased form

Unrecognized selector error for isEqualToString: when setting text of a label

若如初见. 提交于 2019-12-04 05:50:07
问题 I am trying to set the text of a label from one of the properties of my model object ( searchRecipeDetailsVariable ), but I get an error //Extract number of servings from dictionary and place in model self.searchedRecipeDetailsVariable.numberOfServings = [self.detailedSearchYummlyRecipeResults objectForKey: @"numberOfServings"]; //log number of servings to check that it works NSLog(@"Number of Servings, %@",self.searchedRecipeDetailsVariable.numberOfServings); self.numberOfServingsLabel.text

Iphone iterate over substring occurrences of a NSString

半世苍凉 提交于 2019-12-04 05:35:29
I would like to find all occurrences of a substring in a NSString, and iterate one by one to do some changes to that NSString. How should I do it? TheEye How about // find first occurrence of search string in source string NSRange range = [sourceString rangeOfString:@"searchString"]; while(range.location != NSNotFound) { // build a new string with your changed values range = [sourceString rangeOfString:@"searchString" options:0 range:NSMakeRange(range.location + 1, [sourceString length] - range.location - 1)]; } Or just [sourceString stringByReplacingOccurrencesOfString:searchString withString

Convert NSString to ASCII Binary Equivilent (and then back to an NSString again)

对着背影说爱祢 提交于 2019-12-04 05:29:23
问题 I'm having some problems with this. I want to take an NSString and convert it to an integer array of only 0,1 values that would represent the binary equivalent of an ascii string. So for example say I have the following NSString *string = @"A"; // Decimal value 65 I want to end up with the array int binary[8] = {0,1,0,0,0,0,0,1}; then given that I have the binary integer array, how do I go back to an NSString? I know that NSString stores characters as multiple bytes but I only want to use

Compare 2 strings in objective-C

不打扰是莪最后的温柔 提交于 2019-12-04 05:28:55
问题 I wrote the following code: if (depSelectedIndice > -1 && comSelectedIndice> -1) { NSLog(@"depart elemet : %d ",depSelectedIndice); NSLog(@"depart elemet : %d ",comSelectedIndice); NSLog(@"ok1"); NSString *choosedDate =[NSString stringWithFormat:@"%@%@",[deparatureDates objectAtIndex:depSelecif (depSelectedIndice > -1 && comSelectedIndice> -1) { NSLog(@"depart elemet : %d ",depSelectedIndice); NSLog(@"depart elemet : %d ",comSelectedIndice); NSLog(@"ok1"); NSString *choosedDate =[NSString

NSString search whole text for another string

那年仲夏 提交于 2019-12-04 05:27:36
问题 I would like to search for an NSString in another NSString, such that the result is found even if the second one does not start with the first one, for example: eg: I have a search string "st". I look in the following records to see if any of the below contains this search string, all of them should return a good result, because all of them have "st". Restaurant stable Kirsten At the moment I am doing the following: NSComparisonResult result = [selectedString compare:searchText options:

How to truncate an NSString based on the graphical width?

喜夏-厌秋 提交于 2019-12-04 05:18:51
In UILabel there's functionality to truncate labels using different truncation techniques (UILineBreakMode). In NSString UIKit Additions there is a similar functionality for drawing strings. However, I found no way to access the actual truncated string. Is there any other way to get a truncated string based on the (graphical) width for a given font? I'd like to have a category on NSString with this method: -(NSString*)stringByTruncatingStringWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode One option is trying different sizes by looping until you get

What locale argument to pass to NSDecimalNumber +decimalNumberWithString:locale: so it always works with NSString's using the dot (.) decimal mark?

[亡魂溺海] 提交于 2019-12-04 05:08:05
I have an NSString which I want to convert into an NSDecimalNumber . The string is received from a server and is always formatted using the en_US locale like XXX.YYY and not like XXX,YYY . I want to create an NSDecimalNumber which accepts XXX.YYY regardless of the locale the user. The number is never displayed to the user, it's used to do internal math. Normally you'd do something like this: NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithString:@"1.234"]; However, if the user is running the fr_FR locale of Mac OS X, that will break. en_US will interpret it as one point two three four ,

Append a newline to an NSString

家住魔仙堡 提交于 2019-12-04 05:07:32
I have this: if (soapResults != nil) { soapResults = [soapResults stringByAppendingString:@"\n"]; } But I get a warning: Assignment from distinct Objective-C type on build. When I run it on device I get: Program received signal: "EXC_BAD_ACCESS". from gdb. Any ideas how to append a newline to an NSString without getting a warning or error? Any help appreciated // :) An alternative is: [NSString stringWithFormat: @"%@\n", soapResults] even if the logic is the same! However, even in the case of stringByAppendingString, it returns a new string but it doesn't change the target, so you have to