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

  • SEARCH
  • Home
  • 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 8258023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:23:53+00:00 2026-06-08T02:23:53+00:00

I want to implement a delete key for my calculator app. My pseudocode for

  • 0

I want to implement a delete key for my calculator app. My pseudocode for this was:

foo = length of current number
bar = length of current number-1

current number = current number with character at index (foo-bar) removed

To do this in objective-c I have tried to implement this using the NSRange function as well as the StringbyappendingString method:

- (IBAction)DelPressed {
if ([self.display.text length] >=2)
{

    int len = [self.display.text length];//Length of entire display

    //Add to the brainlong printing out the length of the entire display
    self.brainlog.text = [NSString stringWithFormat:@"Len is %g",len];

    int le  = ([self.display.text length]-1);//Length of entire display - 1
    NSString *lestring = [NSString stringWithFormat:@"LE is %g",le];

    //Add to the brainlog printing out the length of the display -1
    self.brainlog.text = [self.brainlog.text stringByAppendingString:lestring];    

    NSRange range = NSMakeRange(le, len);//range only includes the last character

    self.display.text = [self.display.text stringByReplacingCharactersInRange:range withString:@" "];//Replace the last character with whitespace
}

The output to brainlog (ie the length of both le and len) is:

Len is -1.99164 Le is -1.99164

Hard to see, but here’s an image of the number I input to the calculator using the iOS simulator:
iOS sim picture

I have tried to change the value of le (ie making it the length of the display -3 or -5 etc) and both le and len are still the same.

I have also tried to make le in reference to len:

    int len = [self.display.text length];//Length of entire display
    //Add to the brainlong printing out the length of the entire display
    self.brainlog.text = [NSString stringWithFormat:@"Len is %g",len];


    int le = len-1;

But the values of the two are still the same. How can I use NSRange to delete the last character of the display?

Edit: Using Dustin’s fix, I now have reduced a rather lengthy function into 6 lines of code:

    -(IBAction)DelPressed{
    if ([self.display.text length] >=2)
    {
         self.display.text = [self.display.text substringToIndes:[self.display.text length] -1];
    }
 }
  • 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-08T02:23:54+00:00Added an answer on June 8, 2026 at 2:23 am

    Use substring instead; it’s much better if all you want to do is remove the last character.

    More specifically, substringToIndex(/*length-1*/)

    Check this reference out if you need to do other things with strings

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

Sidebar

Related Questions

i'm starter in jqGrid, i want Implement Delete Actin in jqGrid I writing this
I want to implement delete functionality using checkboxes in my struts2 application. I'm using
i starter in jqgrid, i want implement inline edit in jqgrid i have this
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
In my desktop-based WPF-application I want to implement a toolbar with key actions (add,
I want to implement delete column in Android's SQLite. I want to make table
I want to implement delete confirmation dialog using FancyBox. The scenario is to pass
I have customized a UITableViewCell and I want to implement swipe to delete. But
I wang to use jQuery UI to implement a delete confirmation. I want to
I have an MVC3 app for which I want to implement claims support. My

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.