c++/string/substr()字符串截取


substr函數的功能是用於字符串的切剪.

substr是string對象里的操作函數之一.

substr即是substring(截取字串)-sub即是-subtraction減法的含義.

substr的第一個參數是截取開始的位置, 第二個參數是截取的長度.

截取自身的所有字符串代碼:

string content = "hello, world"; content.substr(0, content.length()); 即是截取自身所有. 

位置0表示從自身第一個位置開始截取, content.length()表示截取的數量即是自身的數量.

更多示例子

string content = "hello world";

content.substr(0, 5); // 截取 "hello";

content.substr(6, 5); //截取 = "world"

content.substr(0, content.length()) //截取 = "hello world";


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM