2009年5月14日 星期四

數字轉字串(number to string) 字串轉數字(string to number)

字串轉數值語法為:
int n = int.Parse(str);

ex:
int n= int.Parse("1000");
執行結果>>>> n = 1000

由資料庫抓值後轉數值
int n=int.Parse(row1["PJGOVBUDGET"].ToString());

資料庫抓出來的資料有時為null或空白...執行語法會出錯....
有另一種方法可轉值,語法為:
int n;
int.TryParse(str,out n);

ex:
int n;
int.TryParse(row1["PJGOVBUDGET"].ToString(),out n);

正確來說是 整數轉字串 字串轉整數
integer to string and string to integer
char *itoa(int value, char *buffer, int radix);
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa.html

int atoi ( const char * str );
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html

沒有留言:

張貼留言