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";