Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Create a RegExp for me please?

I need to grab the value of this statement:

var transfer= 5.39;

Which would return 5.39. The 5.39 will be any number, greater then 100 is acceptable, and im not sure if it will always be 2 decimal places.

This is the only occurance of a transfer= in the searched text, so it shouldn't be too difficult to grab this number, I just am unable to make these statements aha. So what it should do is:

Value after "transfer=" and before ";" removing all whitespace.

Thanks!

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    you can using #include <string> to using basic_string (from Standard C++ Library ) to store your statement.

    Assume you have string str="var transter = 5.39;"

    Now we will get the numeric value

    void GetValue(std::string str,double &numeric)

    {

    //Looking for = assignment position in str

    for (int i=0;i<str.length();i++)

    if (str[i]== ' = ' )

    {

    //Get substring from position character after "=" to the end

    string temp=str.substr(i+1);

    //Remove all space and ' ; ' to get string represent numeric

    int k=0;

    while(k<temp.length())

    {

    if (str[k]==' ') str.erase(k,1); //Erase space

    if (str[k]==';') str.earse(k,1); //Erase ;

    k++;

    }

    //Convert string to numeric data

    numeric=atof(temp.c_str());

    return; //Quit

    }

    }

Still have questions? Get your answers by asking now.