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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:05:11+00:00 2026-05-25T03:05:11+00:00

I have an array with file names and I want to find all the

  • 0

I have an array with file names and I want to find all the names that end with e.g. 00001.trc when traceNum is 1. I tried this:

NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH \"%05d.trc\"", traceNum];

and my predicate was SELF ENDSWITH "%05d.trc" instead of SELF ENDSWITH "00001.trc"

I tried this:

NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@%05d.trc%@", @"\"", traceNum, @"\""];

and I got an exception: Unable to parse the format string "SELF ENDSWITH %@%05d.trc%@".

So I tried this:

NSPredicate *tracePredicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"SELF ENDSWITH \"%05d.trc\"", traceNum]];

and it works.

So do I really need stringWithFormat in addition to predicateWithFormat or is there something I’m not doing correctly in creating my predicate?

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

    You’re correct; predicateWithFormat: is not quite the same as stringWithFormat:.

    It’s different for a couple major reasons:

    1. It’s not actually creating a new string. It’s just looking through the format string and seeing what the next thing to substitute is, popping that off the va_list, and boxing it up into the appropriate NSExpression object.
    2. It has to support a format specifier that NSString doesn’t: %K. This is how you substitute in a key path. If you tried to substitute in the name of a property using %@, it would actually be interpreted as a literal string, and not as a property name.
    3. Using formatting constraints (I’m not sure what the proper term is) like the 05 in %05d isn’t supported. For one, it doesn’t make sense. NSPredicate does numerical comparisons (in which case 00005 is the same thing as 5, and thus the zero padding is irrelevant) and string comparisons (in which you can just format the string yourself before giving it to NSPredicate). (It does other comparisons, like collection operations, but I’m skipping those for now)

    So, how do you do what you’re trying to do? The best way would be like this:

    NSString *trace = [NSString stringWithFormat:@"%05d.trc", traceNum];
    NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF ENDSWITH %@", trace];
    

    This way you can do all the formatting you want, but still use the more correct approach of passing a constant string as the predicate format.

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

Sidebar

Related Questions

I have an array of file names which I want to download. The array
I have a FileInfo array with ~200.000 File Entries. I need to find all
In a build.rake file I have an array holding names of JavaScript files: JS_FROM_INDEX=`./bin/extract_files
In my main file I have an array of character strings, char names[320][30], and
I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
All, I am trying to ensure that a file I have open with BufferedReader
Let's say I have a dictionary of names (a huge CSV file). I want
Okay I have a csv file that gets parsed and displayed. I want to
I have a array stored in a PHP file in which I am storing
I have dynamic array filled with bytes, which are read from .raw file with

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.