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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:41:15+00:00 2026-06-17T18:41:15+00:00

I want to be able to find a substring within a sting but it

  • 0

I want to be able to find a substring within a sting but it has a distinctive pattern I am not sure how to find.

EX.

NSString *test1= @"Contact Names
                  67-444-322
                  Dec 21 2012
                  23941 6745 9145072 01567
                  5511 23345 614567 123456
                  Older Contacts
                  See Back Side";

I want to find the following pattern within the substring (these numbers but not date numbers)

                  23941 6745 9145072 01567
                  5511 23345 614567 123456

However, the format of the example string will hardly ever be the same. There will be different numbers and a different title every time other than “Contact Names”, “Older Contacts” and “See Back Side”. One thing that will remain constant is that the numbers I am looking for will always have 4 numbers but there could be 1 row or 10 rows.

Does anyone know how I would go about this problem? I was thinking something in terms of perhaps finding only the numbers within the string and then checking to see which numbers have 3 spaces in between.

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-06-17T18:41:16+00:00Added an answer on June 17, 2026 at 6:41 pm

    You could use character sets to separate the string and then determine if there are 4 numbers in each component. This will only work though if the string has newline characters (\n) in it (as your response to Lance seems to indicate).

    This is how I would go about it:

    NSString *test1= @"Contact Names\n
                  67-444-322\n
                  Dec 21 2012\n
                  23941 6745 9145072 01567\n
                  5511 23345 614567 123456\n
                  Older Contacts\n
                  See Back Side";
    
    NSArray *lines = [test1 componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet];
    
    // lines now contains each line in test1
    
    for (NSString* line in lines) {
    
        NSArray *elements = [line componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet];
    
        if (elements.count == 4) {
            // This line contains 4 numbers
            // convert each number string into an int if needed
        }
    }
    

    Sorry about the long code lines, some of Apple’s selectors are a little on the long side… In any case, if elements has 4 individual (NSString) objects, then it is one of the lines you are seeking and you can manipulate the data as you need.

    EDIT (aside):

    On the topic of Regex (as this question contains the regex tag), yes you could use regular expressions, but Objective-C doesn’t really have a ‘nice’ way of handling them… Regex is more in the domain of scripting languages and languages which have built-in support for it.

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

Sidebar

Related Questions

I've searched for this for a while but have not been able to find
I want to be able to find out if an event is hooked up
I want to be able to find out which DOM elements are present in
I want to be able to use a wildcard in string::find and then fetch
I want to be able to limit Perl's File::Find to a directory depth (below
I want to be able to replicate only the folder structure (not the contents)
I want be able to find tags of items under the a certain category.
I want to be able to find out when a page element is on
I want to be able to find out if the time/date now is between
I want to be able to find entries created a certain number of days

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.