Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8297017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:14:46+00:00 2026-06-08T15:14:46+00:00

The purpose of the code shown below is to take a string from a

  • 0

The purpose of the code shown below is to take a string from a textfield and remove commas and left parentheses, to prepare the contents for conversion to a float. For example, it takes the number 1,234,567 and changes it to 1234567.

The code snippet works, but returns an informational error “Incompatible pointer types assigning to NSMutableString * from String *”

When I use NSString instead of NSMutableString, I get no errors, but the returned value is an empty string.

Using the NSMutableString methodology, what is the problem and how can I change this to eliminate the ‘Incompatible pointer type” error.

NSMutableString *cleanedDataCellTest = [[NSMutableString alloc] initWithString:datacellR2C2.text];
cleanedDataCellTest =  [cleanedDataCellTest stringByReplacingOccurrencesOfString:@"," withString:@""];
cleanedDataCellTest =  [cleanedDataCellTest stringByReplacingOccurrencesOfString:@")" withString:@""];
cleanedDataCellTest =  [cleanedDataCellTest stringByReplacingOccurrencesOfString:@"(" withString:@"-"];
cleanedDataCellTest =  [cleanedDataCellTest stringByReplacingOccurrencesOfString:@" " withString:@""];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:14:49+00:00Added an answer on June 8, 2026 at 3:14 pm

    The stringByReplacingOccurrencesOfString is a method of NSString, and the return value is also a NSString. So you can’t assign the return value to a NSMutableString variable.

    Instead you can use the method replaceOccurrencesOfString:withString:options:range: from NSMutableString:

    NSMutableString *cleanedDataCellTest = [[NSMutableString alloc] initWithString:@"1,234,567"];
    [cleanedDataCellTest replaceOccurrencesOfString:@"," withString:@"" options:0 range:NSMakeRange(0, cleanedDataCellTest.length)];
    [cleanedDataCellTest replaceOccurrencesOfString:@")" withString:@"" options:0 range:NSMakeRange(0, cleanedDataCellTest.length)];
    [cleanedDataCellTest replaceOccurrencesOfString:@"(" withString:@"-" options:0 range:NSMakeRange(0, cleanedDataCellTest.length)];
    [cleanedDataCellTest replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, cleanedDataCellTest.length)];
    

    But, for the consideration of performance, I think use NSString and its method stringByReplacingOccurrencesOfString is more efficient.

    UPDATE: Sorry, yesterday I didn’t test the “performance”. I did a test just now, by replacing some thing in a string (about 26KB), use NSMutableString with replaceOccurrencesOfString:withString:options:range: is a little bit more efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got following (simplified for example purpose) code and it works: void log(const string
The purpose of this code is to pull upgrade.zip from a central server, extract
What is the main purpose of overloading operators in C++? In the code below,
Note The question below was asked in 2008 about some code from 2003. As
The code below is adapted from this answer function MessageClass() { var self =
I have a code file from the boto framework pasted below, all of the
Shown below is a Generic Range class. The purpose of this is to save
Quick question, What have I done wrong here. The purpose of this code is
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
What is the purpose of these java.lang.annotation imports in this code? Why are they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.