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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:19+00:00 2026-05-23T23:37:19+00:00

I am using NSDataDetector to parse a text and retrieve the numbers. Here is

  • 0

I am using NSDataDetector to parse a text and retrieve the numbers. Here is my code:

 NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber
 error:&error];

NSArray *matches = [detector matchesInString:locationAndTitle options:0 range:NSMakeRange(0,[locationAndTitle length])];

for (NSTextCheckingResult *match in matches) {


        if ([match resultType] == NSTextCheckingTypePhoneNumber) {

            self.theNumber = [match phoneNumber];
        }
    }

The problem with this is that it sometime returns something like this:

Telephone: 9729957777
OR
9729957777×3547634

I don’t want that to appear and to remove it would be harder then using a regex code to retrieve the numbers. Do you have any idea on how to retrieve only the number.

  • 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-23T23:37:20+00:00Added an answer on May 23, 2026 at 11:37 pm

    Personally I would just use -substringWithRange: on the string to remove everything past and including the ‘x’ character:

    NSString * myPhoneNum = @"9729957777x3547634";
    NSRange r = [myPhoneNum rangeOfString:@"x"];
    if (r.location != NSNotFound) {
        myPhoneNum = [myPhoneNum substringWithRange:NSMakeRange(0, r.location)];
    }
    NSLog(@"Fixed number: %@", myPhoneNum);
    

    Any idea where the x3547634 comes from, anyway?

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

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using the classic code snippet: if (x & (x-1)) == 0 If the answer
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using the Cocoa Framework, how can I add bullets and numbering to text?
Using a Microsoft version of SQL, here's my simple query. If I query a
I got strange results using NSDataDetector and I am looking for insight in how
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using Ivy with this Ant target: <target name=retrieve-jars> <ivy:retrieve pattern=WebContent/WEB-INF/lib/[artifact].[ext] /> </target> to fetch
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using online interfaces to a version control system is a nice way to have

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.