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 974657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:28:03+00:00 2026-05-16T03:28:03+00:00

I am trying to grab a number from a text box entry, convert it

  • 0

I am trying to grab a number from a text box entry, convert it to string and grab the length of it. (IE: Perform a LEN(someInteger) on a number).

I have been able to get it working, however there are some inconsistencies when the number is 0 or null.

For example;

-(IBAction)update
{
   // inputField is the number pad textbox
   double myInput = [inputField.text doubleValue];

   // 
   NSNumber *c = [NSNumber numberWithDouble:myInput];
   NSString *myOutput  = [c stringValue];

   NSLog(@"Starting number (number) = %@", c);
   NSLog(@"myOutput (string) = %@", myOutput);
   NSLog(@"myOutput (length) = %d", ([myOutput length]) );

}

The conversion for number to string works fine. The problem I have is with the length, especially when there are no numbers (or null) entry.

I have a number pad text box entry on an XIB which has a “text” of 0 (the placeholder just says “Enter number here”)

When you first start typing into the text box the “text” goes away and you start with a blank text box.

Problem 1 — when you first enter the text box there is nothing in the textbox, but my NSLog says the output length is 1 character long.

This causes a problem because visually there is nothing in the textbox but the [myOutput length] reports 1 character length.

Problem 2 — when you start to enter numbers, everything goes well — but when you start to remove numbers to the point where you clear the text box completely it reports a length of 1 character.

How can it read 1 character long if there is nothing in the text box? I think it must be the “text” (From identity inspector) again.

Summary.

  1. There is a number pad text box entry field. Whenever you update the entry, it calls the IBaction update method.

  2. When you first enter numbers into the text box there is nothing visually displayed in the input field, but the NSLog reports the length is 1 character long.

  3. When you start entering numbers and then start to remove them one at a time till you completely remove all numbers it reports the length as being 1 character long.

In both cases the NSLog should be reporting 0 length, but it never does. I tried doing [myOutput length] – 1 but this gives me weird results.

Any help on this would be great

Thanks.

  • 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-05-16T03:28:04+00:00Added an answer on May 16, 2026 at 3:28 am

    If there’s no text, myInput will be equal to 0.0. myOutput will then be equal to @"0", which has a length of 1.

    Why not just use [inputField.text length]?

    You could do something like this:

    NSNumber *number = nil;
    if ([inputField.text length] > 0) {
        number = [NSNumber numberWithDouble:[inputField.text doubleValue]];
    }
    

    That way you have your number if it exists, otherwise number will be nil.

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

Sidebar

Related Questions

I'm trying to grab data from a MySQL database. Approach 2 - apply/map style
I'm just playing around and I'm trying to grab information from websites. Unfortunately, with
I'm trying to write a template that will grab a mixture of text nodes
Im trying to grab a HTML source code from a webpage which needs user
I am trying to grab the data from the database and display all the
I'm trying to grab each URL parameter and display them from first to last,
I am trying to grab the capital letters of a couple of words and
I'm trying to grab a div's ID in the code behind (C#) and set
I'm trying to make an ajax call to grab session data to insert into
I want to disable users from entering a character into a HTML text input

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.