nsmutablestring

error : 'Attempt to mutate immutable object with appendString:' --

南笙酒味 提交于 2019-12-06 02:09:08
I am getting an error 'Attempt to mutate immutable object with appendString:' and my code is NSMutableString *resultString= [[NSMutableString alloc]init]; for (NSMutableString *s in self.ArrayValue) { [resultString appendString:s]; NSLog(resultString); } ArrayValue is NSMutableArray. I am not able to understand where is the problem thank you in advance As posted, the code you have will not give you the error you describe. Probably, somewhere between allocating resultString and the for loop, you are overwriting it with a normal NSSring. Just do have like this: It works for me... NSMutableString

Appending unichar to NSMutableString

家住魔仙堡 提交于 2019-12-05 04:58:24
How do you append a unichar character to NSMutableString ? unichar c = 'T'; NSMutableString *s = [NSMutableString stringWithString:@"MyString"]; // want s to become "MyStringT" https://discussions.apple.com/thread/1679290 suggests: [s appendString:[NSString stringWithCharacters:&c length:1]]; Looks too long / complicated... Use [NSString appendFormat:], so for above: [s appendFormat:@"%C", c]; Enjoy! 来源: https://stackoverflow.com/questions/29357205/appending-unichar-to-nsmutablestring

Objective C: convert a NSMutableString in NSString

混江龙づ霸主 提交于 2019-12-03 06:27:57
问题 I have an NSMutableString, how can I convert it to an NSString? 回答1: 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

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

How to see if an NSString starts with a certain other string?

人走茶凉 提交于 2019-11-29 20:31:52
I am trying to check to see if a string that I am going to use as URL starts with http. The way I am trying to check right now doesn't seem to be working. Here is my code: NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://"]; if ([businessWebsite rangeOfString:@"http"].location == NSNotFound){ NSString *temp2 = [[NSString alloc] init]; temp2 = businessWebsite; [temp appendString:temp2]; businessWebsite = temp2; NSLog(@"Updated BusinessWebsite is: %@", businessWebsite); } [web setBusinessWebsiteUrl:businessWebsite]; Any ideas? Try this: if ([myString hasPrefix:@"http"]) .

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

人盡茶涼 提交于 2019-11-29 09:01:54
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..Please help me.. now question has solved.. Dharmbir Singh Immutable String..... NSString *str1 = @

How to initialize NSString to NSMutableString?

大憨熊 提交于 2019-11-29 07:12:48
Is there any way to initialize NSString to NSMutableString? and also reverse order? -(void)st:(NSString *)st { NSMutableString str = st; // gives warning.. NSLog(@"string: %@", str); } NSString is an immutable representation (or a readonly view at worst). So you would need to either cast to a NSMutableString if you know it's mutable or make a mutable copy: -(void)st:(NSString *)st { NSMutableString *str = [[st mutableCopy] autorelease]; NSLog(@"string: %@", str); } I autoreleased it because mutableCopy returns a newly initialized copy with a retain count of 1. NSString *someImmutableString = @

Position of a character in a NSString or NSMutableString

半城伤御伤魂 提交于 2019-11-29 02:47:48
问题 I have searched for hours now and haven't found a solution for my problem. I have a NSString which looks like the following: "spacer": ["value1", "value2"], "spacer": ["value1", "value2"], ... What I want to do is to remove the [ ] characters from the string. It's seems to be impossible with objective-c. Most other programming languages offer functions like strpos or indexOf which allow me to search for a character or string and locate the position of it. But there seems nothing to be like

How to see if an NSString starts with a certain other string?

落花浮王杯 提交于 2019-11-28 16:54:47
问题 I am trying to check to see if a string that I am going to use as URL starts with http. The way I am trying to check right now doesn't seem to be working. Here is my code: NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://"]; if ([businessWebsite rangeOfString:@"http"].location == NSNotFound){ NSString *temp2 = [[NSString alloc] init]; temp2 = businessWebsite; [temp appendString:temp2]; businessWebsite = temp2; NSLog(@"Updated BusinessWebsite is: %@", businessWebsite);

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.