nsstring

Subclassing NSString

依然范特西╮ 提交于 2019-11-29 15:17:59
Using WSDL2ObjC I am getting lot of classes which are subclasses of NSString. I am finding it troublesome to initialize the NSString value of any object of those classes. Say my class looks like this : @interface mClass ; NSString { int value; } Now in my code I would like to use objects of mClass as both NSString and also want to use its attribute value which is an integer. How can I do that? I am trying to use code like this mClass *obj = [[mClass alloc] initWithString:@"Hello"]; But it's showing me an error saying I am using an abstract object of a class , I should use concrete instance

Why is my sizeWithFont:constrainedToSize:lineBreakMode: always returning zero?

青春壹個敷衍的年華 提交于 2019-11-29 15:15:52
问题 I'm trying to make a UITableViewCell that adjusts its height based on the length of a string it's displaying, but am getting hung up on this method. Here's what I've got: NSString *text = @"A really long string in here"; CGSize theSize = [text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; NSString *stringHeight = [NSString stringWithFormat:@"%d", theSize.height]; No matter what, stringHeight displays as

Composing unicode char format for NSString

五迷三道 提交于 2019-11-29 15:12:47
问题 I have a list of unicode char "codes" that I'd like to print using \u escape sequence (e.g. \ue415 ), as soon as I try to compose it with something like this: // charCode comes as NSString object from PList NSString *str = [NSString stringWithFormat:@"\u%@", charCode]; the compiler warns me about incomplete character code. Can anyone help me with this trivial task? 回答1: I think you can't do that the way you're trying - \uxxx escape sequence is used to indicate that a constant is a unicode

Replace letters in a string

*爱你&永不变心* 提交于 2019-11-29 14:29:36
Hello i have a problem that i don't know how to solve. The problem is that I even don't know how to google about it. I've already spent hours on the internet finding the solution, but didn't succeeded. The situation is like this: I have String, lets say: NSString *string = @"aąbcčdeęėfghiįjzž"; my result has to be like this: NSString *string = @"aabccdeeefghiujzz"; So if you understood i have to do this: replace ą with a replace č with c replace ė with e replace ę with e and so on.. Maybe anyone could help me? i have an answer but it's not very optimized, i am hoping for some more convenient

Encoding spaces in UITextView / UITextField to URL format

喜欢而已 提交于 2019-11-29 14:13:24
问题 I'm trying to send the contents of UITextView or UITextField as parameters to a php file NSString *urlstr = [[NSString alloc] initWithFormat:@"http://server.com/file.php?name=%@&tags=%@&entry=%@",nameField.text, tagsField.text, dreamEntry.text]; When i log urlstr, the url format is ok just as long as the UITextView or UITextField don't contain spaces. How would i go about converting the spaces to %20 ? edit here is the code at present, which not only crashes but isn't encoding the url

Number of characters in an NSString

不打扰是莪最后的温柔 提交于 2019-11-29 14:11:31
问题 I need a way to find the number of characters in an NSString . The nature of my app requires many multi char unicode characters, which presents obvious problems for the length method on NSString . Copied from Apple's developer website: Length Returns the number of Unicode characters in the receiver. - (NSUInteger)length Return Value The number of Unicode characters in the receiver. I do not want the number of characters per se, but rather the number of characters that you would see if the

Check whether an NSString contains a special character and a digit

梦想与她 提交于 2019-11-29 14:09:41
问题 I need to check whether a string contains one uppercase letter, one lower case letter, one integer and one special character. How do I check? 回答1: Without any additional frameworks: NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"] invertedSet]; if ([aString rangeOfCharacterFromSet:set].location != NSNotFound) { NSLog(@"This string contains illegal characters."); } You could also use a regex (this

Sort NSArray of NSStrings like Addressbook on iphone sort

…衆ロ難τιáo~ 提交于 2019-11-29 13:41:48
问题 I have an array of strings (names) and i would like to sort them like how the address book on the iphone sorts them eg: éli -> under E eg: àli -> under A eg: 4li -> under # any suggestions? 回答1: You need to perform a diacritic insensitive comparison against the strings. NSString has a compare:options: method with an option of NSDiacriticInsensitiveSearch . NSArray *array = [NSArray arrayWithObjects:@"éli", @"bob", @"earl", @"allen", @"àli", @"aaron", nil]; NSArray *sorted = [array

Substring with range out of bounds?

情到浓时终转凉″ 提交于 2019-11-29 13:41:27
Okay, so this is a bit confusing (well to me). I have a string that has a single number I want out of it. I have surrounded this number with '/' so that I will be able to get that number out of it later. Here is how I am getting the number out of it: if ([MYSTRING hasSuffix:@"mp"]) { int start = 0; int end = 0; char looking = '/'; for(int i=0; i < MYSTRING.length; i++){ if (looking == [MYSTRING characterAtIndex:i]) { if (start == 0) { start = i; } else{ end = i + 1; } } } NSLog(@"%@", MYSTRING); //When i NSLOG here i get '2012-06-21 03:58:00 +0000/1/mp', 1 is the number i want out of the

Do NSString objects need to be alloc and init?

北城余情 提交于 2019-11-29 13:33:05
Noob question: I'm currently under the impression that when you want to create an object, you need to alloc and init that object. However, I've seen seen several sample codes where an NSString object is declared, yet I see no alloc or init messages following... A very simple example: NSString *myString = @"Hello World"; NSLog(@"%@" , myString); Can someone explain why this is so? Sergio Acosta Declaring a variable does not require releasing any memory. Instantiating objects does. And you only instantiate a new object if you call alloc or copy In your example, you are setting your reference to