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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:31:13+00:00 2026-06-11T16:31:13+00:00

I have a string of format NSString *CalculationFormula = @((Col(202)/Col(201)-1)*100; I need to replace

  • 0

I have a string of format NSString *CalculationFormula = @”((Col(202)/Col(201)-1)*100″;
I need to replace all occurrences of Col(number) with ABC(number * 10)

Please help …

Thanks,
Ben

  • 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-11T16:31:14+00:00Added an answer on June 11, 2026 at 4:31 pm

    There’s some ambiguity in the desired results. For example, should the result be “ABC(202 * 10)” or “ABC(2020)”? I’m going to assume the latter. Since regex is fairly generic, here’s a Perl snippet that accomplishes what I think you want, followed by its translation into Cocoa. I’ve given both, because it’s much easier to see what’s going on there before moving onto NSRegularExpression because the latter has so many more escapes in the pattern.

    Perl version:

    #!/usr/bin/perl -w
    use strict;
    
    
    my $search_text = "((Col(202)/Col(201)-1)*100";
    
    $search_text =~ s|Col\((?P<num>\d+)\)|ABC($+{num}0)|g;
    print $search_text;
    

    Prints: ((ABC(2020)/ABC(2010)-1)*100

    So, the matching pattern is Col\((?P<num>\d+)\) and the substitution pattern ABC($+{num}0

    Cocoa version:

    #import <Foundation/Foundation.h>
    
    int main(int argc, char *argv[]) {
        NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
    
        NSRegularExpression *regex = nil;
        regex = [NSRegularExpression regularExpressionWithPattern:@"Col\\((\\d+)\\)" options:NSRegularExpressionCaseInsensitive error:nil];
        NSString *searchText = @"((Col(202)/Col(201)-1)*100";
        NSString *newText = [regex stringByReplacingMatchesInString:searchText options:0 range:NSMakeRange(0,[searchText length]) withTemplate:@"ABC($10)"];
        NSLog(@"new = %@",newText);
        [p release];
    }
    

    Logs:

    2012-09-18 12:30:26.880 Untitled[22405:707] new = ((ABC(2020)/ABC(2010)-1)*100
    

    Now, if my original assumption was wrong and you literally want “num * 10” in the result,then the substitution pattern is:

    @"ABC($1 * 10)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using String.Format how can i ensure all numbers have commas after every 3 digits
I have a problem I need to convert char [] to String, hexadecimal format
I have NSString in the following format NSString *string1 = @webservices/employee/1; and another string
I hava a format problem in cell-subtitle. I have a string and a number
I have to set a format string for a DateFormatter to convert a NSString
I have a NSString in this format: Key1-Value1,Key2-Value2,Key3-Value3,... I need only keys (with a
I have a method that receives a number in a NSString format. I wish
i have an NSString that is value in plist format. i download this string
I have a date in String format, mm/dd/yyyy I want to convert this to
I have a string in the format yyyymmdd. It is a string in bash

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.