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

  • Home
  • SEARCH
  • 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 4334052
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:28:34+00:00 2026-05-21T10:28:34+00:00

I am trying to write a generic method for String conversion (purpose being I

  • 0

I am trying to write a generic method for String conversion (purpose being I am writing a parser for a RESTful API).

The message aims to convert strings as follows

creationTSZ -> creation_tsz

userId -> user_id

The message handles converting userId -> user_id, currently inefficiently looping through the string and change parts.

It doesn’t yet handle creationTSZ -> creation_tsz, I think looping any further is very inefficient, and am wondering if there’s a better way to do this?

Possibly Regex?

-(NSString *)fieldsQueryString 
{

    NSArray *fieldNames = [self fieldList];

    /* Final composed string sent to Etsy */
    NSMutableString *fieldString = [[[NSMutableString alloc] init] autorelease];

    /* Characters that we replace with _lowerCase */
    NSArray *replaceableChars = [NSArray arrayWithObjects:
                                 @"Q", @"W", @"E", @"R", @"T", @"Y", @"U", @"I", @"O", @"P", 
                                 @"A", @"S", @"D", @"F", @"G", @"H", @"J", @"K", @"L",
                                 @"Z", @"X", @"C", @"V", @"B", @"N", @"M", nil];

    /* Reusable pointer for string replacements */
    NSMutableString *fieldNameString = nil;

    /* Loop through the array returned by the filter and change the names */
    for(NSString *fieldName in fieldNames) {
        /* Loop if the field is to be omited */
        if ([[self valueForKey:fieldName] boolValue] == NO) continue;
        /* Otherwise change the name to a field and add it */
        fieldNameString = [fieldName mutableCopy];
        for(NSString *replaceableChar in replaceableChars) {
            [fieldNameString replaceOccurrencesOfString:replaceableChar 
                                             withString:[NSString stringWithFormat:@"_%@", [replaceableChar lowercaseString]] 
                                                options:0 
                                                  range:NSMakeRange(0, [fieldNameString length])];
        }
        [fieldString appendFormat:@"%@,", fieldNameString];
        [fieldNameString release];
    }
    fieldNames = nil;

    /* Return the string without the last comma */
    return [fieldString substringToIndex:[fieldString length] - 1];
}
  • 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-21T10:28:35+00:00Added an answer on May 21, 2026 at 10:28 am

    Assuming that your identifiers are structured like

    <lowercase-prefix><Uppercase-char-and-remainder>
    

    you could use:

    NSScaner *scanner = [NSScanner scannerWithString:fieldName];
    NSString *prefix = nil;
    [scanner scanCharactersFromSet:[NSCharacterSet lowercaseLetterCharacterSet] intoString:&prefix];
    NSString *suffix = nil;
    [scanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet] intoString:&suffix];
    NSString *fieldNameString = [NSString stringWithFormat:@"%@_%@", prefix, [suffix lowercaseString]];
    

    This would perform the conversion of field identifiers (but you should perform some error checking in case either prefix or suffix stay nil).

    The easiest way to build the list of fieldNames would be add them to a NSMutableArray, and to then join them:

    NSMutableArray *fields = [[NSMutableArray alloc] init];
    for (NSString *fieldName in [self fieldList]) {
        // code as above
        [fields add:fieldNameString];
    }
    NSString *commaFields = [fields componentsJoinedByString:@","];
    [fields release];
    return commaFields;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a generic Parse method that converts and returns a
I am trying to write a unit test for an action method which calls
I'm trying to write a REST-API server with NodeJS like the one used by
I am trying to write my didReceiveMemoryWarning method. Should I simply set my IBOutlets
I'm trying write a query to find records which don't have a matching record
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a blog post which includes a code segment inside a
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write some PHP to upload a file to a folder on

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.