J
Jay
I need to convert from a string a double that is followed by a scaling character (k means *1e3,
M=*1e6, etc) then apply the scaling character. Example:
"-1.345k #comment"
I know roughly how to do this in C (using the %n in the sscanf format specifier to find the number
of characters converted) , but how do I do it in C#? My problem is how to count the number of
characters of the double (chpos in the C example) so that the scaling character can be easily found.
/* C-code example */
double doub;
int n, nchar, chpos=0
char str[] = "-1.345k #comment"
n=sscanf"(&str[chpos], "%lf%n", &doub, &nchar);
if(n==0){
... code to deal with invalid double
}else
chpos += nchar;
if(str[chpos]='k'){
doub *= 1e6;
}
...
}
M=*1e6, etc) then apply the scaling character. Example:
"-1.345k #comment"
I know roughly how to do this in C (using the %n in the sscanf format specifier to find the number
of characters converted) , but how do I do it in C#? My problem is how to count the number of
characters of the double (chpos in the C example) so that the scaling character can be easily found.
/* C-code example */
double doub;
int n, nchar, chpos=0
char str[] = "-1.345k #comment"
n=sscanf"(&str[chpos], "%lf%n", &doub, &nchar);
if(n==0){
... code to deal with invalid double
}else
chpos += nchar;
if(str[chpos]='k'){
doub *= 1e6;
}
...
}