字母和數字轉換

2022-05-17 11:39:09 字數 2534 閱讀 6724

字母和數字之間的轉換利用ascii進行轉換

a --> 97 int(a) 或者a+0

97--> a char(97) 1的ascii為49

1 --> '1' char('1'的ascii)

字母轉數字, int(字母)

數字轉字母 char(數字) 該數字 對應字母的ascii

#include #include 

#include

using

namespace

std;

intmain()

#if 0字母和數字之間的轉換利用ascii進行轉換

a --> 97

int(a) 或者a+0

97--> a char(97

) 1的ascii為49

1 --> '1'

char('1'

的ascii)

字母轉數字,

int(字母)

數字轉字母

char

(數字) 該數字 對應字母的ascii

#endif

return0;

}

方法一:

用stringstream 類

1 #include 2 #include 

3 #include 4 #include 5

using

namespace

std;67

intmain()

1 #include 2 #include 

3 #include 4 #include 5 #include 6

using

namespace

std;78

intmain()

123.32

nst7__cxx1118basic_stringstreamicst11char_traitsicesaiceee

整型--->字串

1 #include 2 #include 

3using

namespace

std;45

intmain()

浮點型

1 #include 2 #include 

3using

namespace

std;45

intmain()

用sscanf函式

1 #include 2 #include 

3using

namespace

std;45

intmain()

1 (1)string --> char *

2string str("ok"

);3char * p =str.c_str();

45 (2)char * -->string

6char *p = "ok"

;7string

str(p);

89 (3)char * -->cstring

10char *p ="ok"

;11cstring m_str(p);

12//

或者13

cstring m_str;

14 m_str.format("%s"

,p);

1516 (4)cstring --> char *

17 cstring str("ok"

);18

char * p = str.getbuffer(0

);19

...20

str.releasebuffer();

2122 (5)string -->cstring

23 cstring.format("

%s", string

.c_str());

2425 (6)cstring --> string

26string s(cstring.getbuffer(0

));

27getbuffer()後一定要releasebuffer(),否則就沒有釋放緩衝區所佔的空間,cstring物件不能動態增長了。

2829 (7)double/float->cstring

30double

data;

31 cstring.format("

%.2f

",data); //

保留2位小數

3233 (8)cstring->double

34 cstring s="

123.12";

35double d=atof(s);

3637 (9)string->double

38double d=atof(s.c_str());

sql 提取中文和數字字母

需要去除特殊符號換言之 只取中文數字字母即可 注意 下面的 吖 座 不是亂碼 就這樣寫.create function dbo fn isnotspecial str varchar 8000 returns varchar 500 as begin while patindex 吖 座a za z...

C 判斷是否為字母和數字

1 庫檔案 include 2 isdigit 數字返回非0,非數字返回0 3 isalpha 字母返回非0,非字母返回0 4 使用for迴圈對string的每個元素進行判斷。檔名 作業 描述 設計程式,提示使用者輸入一串 只包含英文或數字 字元,然後程式列印使用者輸入字串的第乙個字元,迴圈執行這樣...

mysql 日期轉換和數字格式轉換

時間轉成年月日時分秒 select date format now y m d h i s 時間轉成年月日 select date format now y m d 去年此時 select date add now interval 1 year 上月此時 select date add now i...