下面的示例阐释了 substr 方法的用法。 function SubstrDemo(){ var s, ss; //Declare variables. var s = "The rain in Spain falls mainly in the plain."; ss = s.substr(12, 5); //Get substring. return(ss); // Returns "Spain". ----------------------------------------------crazyghost_von补充----------------------------------------------------------------------- s.substr(12)的结果是 Spain falls mainly in the plain. ---------------------------------------------------------------------------------------------------------------------------------------------- Code : C++中 的代码如下 // basic_string_substr.cpp // compile with: /EHsc #include <string> #include <iostream> using namespace std; int main( ) { using namespace std; string str1 ("Heterological paradoxes are persistent."); cout << "The original string str1 is: \n " << str1 << endl << endl; basic_string <char> str2 = str1.substr ( 6 , 7 ); cout << "The substring str1 copied is: " << str2 << endl << endl; basic_string <char> str3 = str1.substr ( ); cout << "The default substring str3 is: \n " << str3 << "\n which is the entire original string." << endl; 输出结果: The original string str1 is: Heterological paradoxes are persistent. The substring str1 copied is: logical The default substring str3 is: Heterological paradoxes are persistent. which is the entire original string. } 在oracle中的用法: SUBSTR(:NEW.FLAGSTATUS,17,1) 其中参数依次是 ( 串,开始,长度),并返回子串。