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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:28:22+00:00 2026-05-25T13:28:22+00:00

I have a NSString in this format: Key1-Value1,Key2-Value2,Key3-Value3,… I need only keys (with a

  • 0

I have a NSString in this format:

“Key1-Value1,Key2-Value2,Key3-Value3,…”

I need only keys (with a space after every comma):

Key1, Key2, Key3, etc.

I thought to create an array of components from the string using the comma as separator, and after, for every component, extract all characters since the “-“; then I’d serialize the array elements. But I fear this could be very heavy about performances.

Do you know a way to do this using regular expressions?

  • 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-25T13:28:23+00:00Added an answer on May 25, 2026 at 1:28 pm

    The regex will greatly depend on the data you are using. For example if the key or value is allowed to be all numbers, or allowed to contain space and punctuation, you would need to modify the regex. For your current example however this will work.

    NSString *example = @"Key1-Value1,Key2-Value2,Key3-Value3,...";
    NSString *result = [example stringByReplacingOccurrencesOfString:@"(\\w+)-(\\w+),?" 
                                                          withString:@"$1, " 
                                                             options:NSRegularExpressionSearch
                                                               range:NSMakeRange(0, [example length])];
    result = [result stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@", "]];
    NSLog(@"%@", result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello all i have one NSString in this format +1-123-123-1234 (phone number US base
i have an NSString that is value in plist format. i download this string
I have a NSString like this NSString *mystring = @RahulVyas; Now I want to
I have a protocol in Objective-C, something like this: @protocol Handler +(NSString*) getValue; @end
I have an NSString which is splitted into set of characters. I need to
I have this date and time format: 2010-05-19 07:53:30 and would like to change
Assume I have a method with the signature: + (NSString *) myFormattedString:(NSString *)format, ...;
I have NSString in the following format NSString *string1 = @webservices/employee/1; and another string
I have a NSString value of @78000. How do I get this in currency
I have a NSString (ex. 2011-04-12 19:23:39), and what I did to format it

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.