Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI
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 9-Jan-12 10:11am
Rezame951
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you now the format of the data could you use simply: sscanf[^]
  Permalink  
Comments
Rezame at 10-Jan-12 5:10am
   
Hi,
Thanks. I used above function but not return correct number.
Regards,
Mika Wendelius at 10-Jan-12 14:25pm
   
What kind of format did you use?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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++.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can use Tokenize[^] metod from CString to split the string and try to select only the number part
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can make a function that parses the string
 
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
  Permalink  
v2

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 231
3 Sergey Alexandrovich Kryukov 211
4 kbrandwijk 204
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 405
4 thatraja 370


Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 11 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100