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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:51:06+00:00 2026-05-27T06:51:06+00:00

Basically I’m working on something that looks like the phone apps keypad. Everything else

  • 0

Basically I’m working on something that looks like the phone apps keypad. Everything else is inputting as it should but what I’m trying to figure out is how on this last one to get it when a 1 is inputted first that the number would look like 1 (555) 555-5555. I’m sure my code will need some tweaking to the substringfromindexes to get it to match up, but what I’m trying to get to happen now is just to check if the entered strings first number is a one or not. Because if it is not it will just bypass this part of code.

else if ([self.self.enteredPhoneNumberString length] == 11 && [self.enteredPhoneNumberString characterAtIndex:0] == '1') {
        NSString *firstNum = [self.enteredPhoneNumberString substringToIndex:1];
        NSString *createFirst = [self.enteredPhoneNumberString substringFromIndex:3];
        NSString *firstThree = [createFirst substringToIndex:3];
        NSString *createSecond = [self.enteredPhoneNumberString substringFromIndex:3];
        NSString *secondThree = [createSecond substringToIndex:3];
        NSString *lastSet = [self.enteredPhoneNumberString substringFromIndex:6];
        self.label.text = [NSString stringWithFormat:@"%@ (%@) %@-%@", firstNum, firstThree, secondThree, lastSet];
    }

If you know of the way to adjust the substrinFromIndex to get the effect I’m going for too by all means that would save me time tampering until I find the right order. Thanks in advance for all help. 🙂

Oh and btw with the above code it did a breakpoint when I got to the this part in the code.

FIX:

Thanks for all the help it works now. Ended up doing this and for some reason the breakpoint doesnt happen when it is done here.

else if ([self.self.enteredPhoneNumberString length] >= 11 ) {
    if ([self.enteredPhoneNumberString characterAtIndex:0] == '1' && [self.self.enteredPhoneNumberString length] == 11) {
        NSString *firstNum = [self.enteredPhoneNumberString substringToIndex:1];
        NSString *createFirst = [self.enteredPhoneNumberString substringFromIndex:1];
        NSString *firstThree = [createFirst substringToIndex:3];
        NSString *createSecond = [self.enteredPhoneNumberString substringFromIndex:4];
        NSString *secondThree = [createSecond substringToIndex:3];
        NSString *lastSet = [self.enteredPhoneNumberString substringFromIndex:7];
        self.label.text = [NSString stringWithFormat:@"%@ (%@) %@-%@", firstNum, firstThree, secondThree, lastSet];
    }
    else{
       self.label.text = [NSString stringWithFormat:@"%@", enteredPhoneNumberString]; 
    }
}

And ya it does seem pointless to have to check if the length is 11 again, but because it was causing issues the previous way I didnt really have much of a choice because I needed it to know whether it exceeded 11 or not so it could start doing that else.

  • 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-27T06:51:06+00:00Added an answer on May 27, 2026 at 6:51 am

    It could be the if statement above where your code starts is true…

    else if ([self.self.enteredPhoneNumberString length] == 11 && [self.enteredPhoneNumberString characterAtIndex:0] == '1') {
    

    needs some cleaning up. You shouldn’t check for length 11 here, just check for length > 0 and whether first character is a 1. Do the necessary formatting, trim white space and (), then check the length.
    Also, self.self is a potential problem, drop the second self

    Please disregard CocoaFu’s comment his solution is better, but the comment is misleading.

    In the following code, my log statement shows up in the console

    NSString * test = [NSString stringWithString:@"test"];
    unichar c = [adjusted characterAtIndex:0];
    
    if (c == 't')   {
        NSLog(@"can compare char");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically from a database I am getting data that is formatted like this nameofproject101
Basically, I would like a page that consist of a slideshow that contains a
Basically, I'm working on a spam detection system and I would like to detect
Basically my rewrite rules work fine but if I am working with files or
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically, I would like a brief explanation of how I can access a SQL
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically I am trying to do this: <Trigger Property=Item Value={c:CollectionView.NewItemPlaceHolder}> But the syntax is

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.