QT字串格式轉換

2021-10-07 14:06:02 字數 1536 閱讀 7790

常用函式彙總:

int qstring::

toint

(bool

*ok = q_nullptr,

int base =10)

const

long qstring::

tolong

(bool

*ok = q_nullptr,

int base =10)

const

short qstring::

toshort

(bool

*ok = q_nullptr,

int base =10)

const

uint qstring::

touint

(bool

*ok = q_nullptr,

int base =10)

const

ulong qstring::

toulong

(bool

*ok = q_nullptr,

int base =10)

const

//轉換為浮點數

float qstring::

tofloat

(bool

*ok = q_nullptr)

const

double qstring::

todouble

(bool

*ok = q_nullptr)

const

使用示例:

qstring str

("520");

int num = str.

toint()

;

常用函式:

qstring number

(long n,

int base =10)

qstring number

(uint n,

int base =10)

qstring number

(int n,

int base =10)

qstring number

(ulong n,

int base =10)

qstring number

(qlonglong n,

int base =10)

qstring number

(qulonglong n,

int base =10)

//浮點數轉換成字串

qstring number

(double n,

char format =

'g',

int precision =

6)

由於cout並不支援qstring型別資料的輸出,因此需要進行轉換

qstring str =

"abcd"

cout

<

轉換字串格式

轉換字串格式為原來字串裡的字元 該字元連續出現的個數,例如字串 1233422222 轉換為1121324125 1出現1次,2出現1次,3出現2次,4出現1次,2出現5次 解法 可通過sprintf語句,位於標頭檔案中。與printf在用法上幾乎一樣,只是列印的目的地不同而已,前者列印到字串中,後...

json字串格式轉換

1.物件相互轉換 物件轉字串 user user newuser jsonobject object jsonobject.fromobject user string jsonstr object.tostring 字串轉物件 jsonobject jsonobj jsonobject.fromo...

Python字串格式轉換

轉換型別 說明d,i 帶符號十進位制 b無符號二進位制 o無符號八進位制 u無符號十進位制 x無符號十六進製制 小寫 x無符號十六進製制 大寫 e科學計數法表示的浮點數 小寫 e科學計數法表示的浮點數 大寫 f,f 十進位制浮點數 g指數大於 4或者小於精度則與e相同,否則與f相同 g指數大於 4或...