字串處理函式

2021-09-01 10:01:24 字數 1598 閱讀 3660

教你mysql資料庫中字串的處理方法,

字串類

charset(str) //返回字串字符集

concat (string2 [,... ]) //連線字串

instr (string ,substring ) //返回substring首次在string中出現的位置,不存在返回0

lcase (string2 ) //轉換成小寫

left (string2 ,length ) //從string2中的左邊起取length個字元

length (string ) //string長度

load_file (file_name ) //從檔案讀取內容

locate (substring , string [,start_position ] ) 同instr,但可指定開始位置

lpad (string2 ,length ,pad ) //重複用pad加在string開頭,直到字串長度為length

ltrim (string2 ) //去除前端空格

repeat (string2 ,count ) //重複count次

replace (str ,search_str ,replace_str ) //在str中用replace_str替換search_str

rpad (string2 ,length ,pad) //在str後用pad補充,直到長度為length

rtrim (string2 ) //去除後端空格

strcmp (string1 ,string2 ) //逐字元比較兩字串大小,

substring (str , position [,length ]) //從str的position開始,取length個字元,

注:mysql資料庫中處理字串時,預設第乙個字元下標為1,即引數position必須大於等於1

01.mysql> select substring('abcd',0,2);

02.+-----------------------+

03.| substring('abcd',0,2) |

04.+-----------------------+

05.| |

06.+-----------------------+

07.1 row in set (0.00 sec)

08.mysql> select substring('abcd',1,2);

09.+-----------------------+

10.| substring('abcd',1,2) |

11.+-----------------------+

12.| ab |

13.+-----------------------+

14.1 row in set (0.02 sec)

15.trim([[both|leading|trailing] [padding] from]string2) 去除指定位置的指定字元

ucase (string2 ) //轉換成大寫

right(string2,length) //取string2最後length個字元

space(count) //生成count個空格

字串處理函式

1 puts 向顯示器輸出字串 原型 int puts const char s 標頭檔案 include 返回值 成功返回輸出的字元數,失敗返回eof puts 函式與printf 輸出字串的區別 1.puts在輸出字串時,遇到 0 會自動終止輸出,並將 0 轉換為 n 來輸出 2.printf在...

字串處理函式

puts 函式 用來向標準輸出裝置 螢幕 寫字串並換行,其呼叫格式為 puts s 其中s為字串變數 字串陣列名或字串指標 puts 函式的作用與語printf s n s 相同,將緩衝區的字元輸出到標準輸出,遇到空字元截至,並且在末尾新增乙個換行符。gets 函式用來從標準輸入裝置 鍵盤 讀取字串...

字串處理函式

下面介紹幾個最常用的字串函式。格式 puts 字元陣列名 功能 把字元陣列中的字串輸出到顯示器。即在螢幕上顯示該字串。例7 12 include stdio.h main 從程式中可以看出puts函式中可以使用轉義字元,因此輸出結果成為兩行。puts函式完全可以由printf函式取代。當需要按一定格...