Questions tagged [nsmutablestring]

The NSMutableString class declares the programmatic interface to an object that manages a mutable string — that is, a string whose contents can be edited — that conceptually represents an array of Unicode characters.

To construct and manage an immutable string — or a string that cannot be changed after it has been created — use an object of the NSString class.

The NSMutableString () class adds one primitive method

-replaceCharactersInRange:withString:

to the basic string-handling behavior inherited from NSString . All other methods that modify a string work through this method.

More information : NSMutableString Class reference

306 questions
160
votes
5 answers

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

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]…
Rob
  • 2,319
  • 4
  • 20
  • 18
70
votes
2 answers

Objective C: convert a NSMutableString in NSString

I have an NSMutableString, how can I convert it to an NSString?
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
38
votes
3 answers

Appending to the end of a file with NSMutableString

I have a log file that I'm trying to append data to the end of. I have an NSMutableString textToWrite variable, and I am doing the following: [textToWrite writeToFile:filepath atomically:YES encoding:…
Julian Coltea
  • 3,599
  • 10
  • 26
  • 32
17
votes
7 answers

What is the best way to initialize NSMutableString object?

If I take a following question. What is the best way to initialize NSMutableString Class? (All instance will be return at unexpected times... so I'll assume that the initialization as follows:) If I know in advance the amount of work. ( expected…
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
13
votes
2 answers

String is not convertible to NSMutableString

It works fine to cast a Swift String as an NSString. let string = "some text" let nsString = string as NSString But when I do let string = "some text" let nsMutableString = string as NSMutableString I get the error 'String' is not convertible…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
13
votes
2 answers

Position of a character in a NSString or NSMutableString

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…
Dominik
  • 193
  • 1
  • 2
  • 5
12
votes
4 answers

Append string with variable

I'm a java guy coming over to Objective-C. In java, to add a variable to a string you'd have to do something along the lines of: someString = "This string is equal to " + someNumber + "."; I can't figure out how to do it in Objective-C though. I…
Peter Kazazes
  • 3,600
  • 7
  • 31
  • 60
11
votes
1 answer

Getting issue on strokeWidth NSAttributedString in iOS 14

I have an issue with stroke color on iOS 14. let attributes: [NSAttributedString.Key: Any] = [ .foregroundColor: UIColor.white, .strokeColor: UIColor.black, .font: UIFont.systemFont(ofSize: 65, weight: .black), .strokeWidth: -1…
vikas prajapati
  • 1,868
  • 2
  • 18
  • 26
10
votes
4 answers

How to use appendFormat to format a string in Swift?

I want to append a string to a NSMutableString using appendFormat, inserting white spaces to get a minimum length for my string. In objective-c, i just used [text.mutableString appendFormat:@"%-12s", "MyString"]; and I would get "MyString " But…
kobuchi
  • 420
  • 5
  • 11
8
votes
2 answers

Clearing rather than releasing a NSMutableString

I've got a rather large loop that gets a string, does something to it, than goes onto the next one. I was originally releasing it then reallocating it but thought that is a bit of waste of resources but can't figure out how to just clear it out to…
Rudiger
  • 6,749
  • 13
  • 51
  • 102
8
votes
1 answer

Appending unichar to NSMutableString

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…
mllm
  • 17,068
  • 15
  • 53
  • 64
8
votes
6 answers

Defining NSMutableString?

My understanding is that both of these create a NSMutableString, only the first one is owned by the system and the second one is owned by me (i.e. I need to release it). Is there any particular reason why I should use one or the other, on the face…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
7
votes
4 answers

Why does [NSMutableString stringWithString:@""] work?

Just wondering: In NSString there is a static method called +stringWithString:. This is not redeclared/overridden in NSMutableString so we cannot assume that this will return an NSMutableString. In fact even in the NSString class the return type is…
Joris Mans
  • 6,024
  • 6
  • 42
  • 69
7
votes
7 answers

NSStrikethroughStyleAttributeName , How to strike out the string in iOS 10.3?

I have used this line of code before release of iOS 10.3 ,and worked fine. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]]; [attributeString…
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47
7
votes
1 answer

Add several attributes to a NSMutableAttributedString

I'm trying to add several attributes to a NSMutableAttributedString; i tried this: let stringNumero: NSString = "\(squadra.cori.count)" //= two-digit number var stringNumeroMutable = NSMutableAttributedString() stringNumeroMutable =…
Fabio Cenni
  • 841
  • 3
  • 16
  • 30
1
2 3
20 21