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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:49:05+00:00 2026-05-27T07:49:05+00:00

I have a required where i need to extract a number from a string

  • 0

I have a required where i need to extract a number from a string in the needed format like :

  • f001–>100
  • f100–>1
  • 2030–>302
  • 0203–>3020
  • 2031–>1302

so the operation above is :

  • remove any f character if it is present
  • reverse the string
  • remove leading zeros from the string

I have written a code which is working fine in c++:

int main(int argc,char* argv[])
{

string str1(argv[argc-1]);


reverse(str1.begin(),str1.end());
str1.erase(remove(str1.begin(),str1.end(),'f'),str1.end());
str1.erase(0,str1.find_first_not_of('0',0));

cout <<str1<<endl;

return 0;

}

is there any better way of doing the same thing?

  • 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-27T07:49:06+00:00Added an answer on May 27, 2026 at 7:49 am

    I Guess, a simple function as below will do the job

    NOTE:- It is not a complete program. Just a flow… It will parse the string once in stead of 3 times as in your case. I definitely hope there are better C++ style approach, and looking forward to the same.

    foo(char* str) {

    int state=0;

    int len=strlen(str);

    for(i=len-1; i>=0; i++) {

    if(state==0 && str[i]!='0') { //Ignore trailing zeros
        state=1;
    }
    else if(stare==1) {
        if(str[i]=='f')
            break;
        //Reverse logic here, just store the char in a heap as it comes which will be returned after the for finishes
    }  
    

    }

    }

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

Sidebar

Related Questions

I have a database from where i need to extract quite a lot of
I have a thunderbird email data file from which I need to extract individual
I'm required to write a JCE provider. I have learned that I need to
After spliting a tab delimited file I have my required values in a string
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
All, I have the following html as a string in javascript. I need to
I need to extract all the bits from a QString that holds a UTF-8
I have a console application that require to use some code that need administrator
In the past, some of my projects have required me to create a movie
Unfortunately we do not have the required DCOM access to the SQL Server mentioned

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.