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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:04:24+00:00 2026-06-13T13:04:24+00:00

I have a file called Strings.h, that I use to localize an app I

  • 0

I have a file called Strings.h, that I use to localize an app I have. I want to search through all of my class files, and find out if and where I am using each string, and output the classes and line numbers for each string.

My thought is to use Python, but maybe that’s the wrong tool for the job. Also, I have a basic algorithm, but I worry it will take too long to run. Can you write this script to do what I want, or even just suggest a better algorithm?

Strings.h looks like this:

#import "NonLocalizedStrings.h"

#pragma mark Coordinate Behavior Strings
#define LATITUDE_WORD NSLocalizedString(@"Latitude", @"used in coordinate behaviors")
#define LONGITUDE_WORD NSLocalizedString(@"Longitude", @"used in coordinate behaviors")
#define DEGREES_WORD NSLocalizedString(@"Degrees", @"used in coordinate behaviors")
#define MINUTES_WORD NSLocalizedString(@"Minutes", @"Used in coordiante behaviors")
#define SECONDS_WORD NSLocalizedString(@"Seconds", @"Used in DMSBehavior.m")

...

The script should take each line that starts with #define, and then make a list of the word that appears after #define (e.g.) LATITUDE_WORD

The pseudocode might be:

file = strings.h
for line in file:
  extract word after #define
  search_words.push(word) 

print search_words
[LATITUDE_WORD, LONGITUDE_WORD, DEGREES_WORD, MINUTES_WORD, SECONDS WORD]

After I have the list of words, my pseudocode is something like:

found_words = {}
for word in words:
   found_words[word] = []

for file in files:
  for line in file:
    for word in search_words:
      if line contains word:
        found_words[word].push((filename, linenumber))   

print found_words

So, found words would look something like:

 {
   LATITUDE_WORD: [
                    (foo.m, 42),
                    (bar.m, 132) 
                  ],
   LONGITUDE_WORD: [
                    (baz.m, 22),
                    (bim.m, 112) 
                  ],

 }
  • 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-13T13:04:25+00:00Added an answer on June 13, 2026 at 1:04 pm

    How about this [in bash] ?

    $ pattern="\\<($(grep '^#define ' Strings.h | cut -d' ' -f2 | tr '\n' '|' | sed 's/|$//'))\\>"
    $ find project_dir -iname '*.m' -exec egrep -Hno "${pattern}" {} + > matches
    

    Output:

    project_dir/bar.m:132:LATITUDE_WORD
    project_dir/baz.m:22:LONGITUDE_WORD
    project_dir/bim.m:112:LONGITUDE_WORD
    project_dir/foo.m:42:LATITUDE_WORD
    

    EDIT: I’ve altered the code above to redirect it’s output to a file matches, so we can use that to show words that are never found:

    for word in $(grep '^#define ' Strings.h | cut -d' ' -f2)
    do
        if ! cut -d':' -f3 matches | grep -q "${word}"
        then
            echo "${word}"
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called middle.config that is deployed in the same directory as
I have a file (called print_1012720.txt ) that looks like the text shown below.
I have a file called file1.txt: dir1 dir2 dir3 ... I wanted to use
I have a file called header.php that I am including on every page on
I have a file called error.log on my server that I need to frequently
I have a file called something like FILE-1.txt or FILE-340.txt. I want to be
I have a file that is called header (the header of my site).. I
I have classA that has some variables declared in its .h file (arrays, strings,
I have created an object called Project that has different properties (strings and some
I have a file called messages.properties which has lines with syntax <key>=<string> . Each

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.