Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I have one csv file that some columns are include parameters same "TakeProfit_II=440"
I read data and save all in vector. I want know how to extract digit than this string.
For example extract 440 than "TakeProfit_II=440"
Regards,
Posted

If you now the format of the data could you use simply: sscanf[^]
 
Share this answer
 
Comments
Rezame 10-Jan-12 5:10am    
Hi,
Thanks. I used above function but not return correct number.
Regards,
Wendelius 10-Jan-12 14:25pm    
What kind of format did you use?
You can use boost lexcical_cast.
Below is the link:
Boost Lexical cast[^]
Use this if your are already having boost. Else boost is a mega download. But boost is very good if you really want to work in hardcore C++.
 
Share this answer
 
You can use Tokenize[^] metod from CString to split the string and try to select only the number part
 
Share this answer
 
v2
You can make a function that parses the string

C++
char *str="TakeProfit_II=440"
int value = get_value(str);

...

int get_value(char *str)
{
     char *value_str = new char[10];
     int index1 = 0;
     int index2 = 0;
     int i = 0;
     int val = 0;
     
     while(str[index1] != '=')
     {
          index1++;
     }
     
     for(i = index1+1 ; i < strlen(str) ; i++)
     {
          value_str[index2] = str[i];
          index2++;
     }

     value_str[index2] = NULL;

     val = atoi(value_str);
     delete []value_str;
     return val; 

}


I hope it helps.

Best regards
Filipe
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900