複製鏈接
請複製以下鏈接發送給好友

substring

鎖定
substring
public String substring(int beginIndex)
返回一個新的字符串,它是此字符串的一個子字符串。該子字符串始於指定索引處的字符,一直到此字符串索引末尾。在SQLserver數據庫中,用於截取字符串的某部分。
中文名
截取字符串
外文名
substring

substring數據庫

SQLserver數據庫
用於截取字符串的某部分,其基本語法為 select substring(字符串或者列名,起始位置,截取長度) from 表。
例如:
select substring(‘ename’,3,2) from emp;
結果為‘am’。

substringJava

簡介
例如:
"unhappy".substring(2)returns"happy"
"Harbison".substring(3)returns"bison"
"emptiness".substring(9)returns""(anemptystring)
參數:
beginIndex - 開始處的索引(包括)。
返回:
指定的子字符串。
拋出:
IndexOutOfBoundsException - 如果 beginIndex 為負或大於此 String 對象的長度。
--------------------------------------------------------------------------------
substring
public String substring(int beginIndex, int endIndex)
返回一個新字符串,它是此字符串的一個子字符串。該子字符串從指定的 beginIndex 處開始, endIndex:到指定的 endIndex-1處結束。
示例:
"hamburger".substring(3,8) returns "burge"
"smiles".substring(0,5) returns "smile"
參數:
beginIndex - 開始處的索引(包括)。
endindex 結尾處索引(不包括)。
返回:
指定的子字符串
拋出:
IndexOutOfBoundsException - 如果 beginIndex 為負,或length大於字符串長度。
javascript示例
<scripttype="text/javascript">
var str="Helloworld!"
document.write(str.substring(1,3));
</script>
上面返回字符串:"el";
str.substring(1,2) //返回e
str.substring(1) //返回"elloworld";
還有此函數中會出現奇怪的現象,當出現str.substring(5,0);
這又是怎麼回事,不過返回的是"Hello",
str.substring(5,1) //返回"ello",截去了第一位,返回餘下的.
可見substring(start,end),可以有不同的説明,即start可以是要返回的長度,end是所要去掉的多少個字符(從首位開始).
在JS中,substr(start,length),用得較方便.

substringC#中

變量.Substring(參數1,參數2);
截取字串的一部分,參數1為左起始位數,參數2為截取幾位。
如:string s1 = str.Substring(0,2);
C#中有兩個重載函數
舉例如下代碼,VS2005編譯通過
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespacesln_sub
{
classProgram
{
staticvoidMain(string[]args)
{
stringmyString="Aquickfoxisjumpingoverthelazydog";
//Substring()在C#中有兩個重載函數
//分別如下示例
stringsubString1=myString.Substring(0);
//如果傳入參數為一個長整,且大於等於0,
//則以這個長整的位置為起始,
//截取之後餘下所有作為字串.
//如若傳入值小於0,
//系統會拋出ArgumentOutOfRange異常
//表明參數範圍出界
stringsubString2=myString.Substring(0,11);
//如果傳入了兩個長整參數,
//前一個為參數子串在原串的起始位置
//後一個參數為子串的長度
//如不合條件同樣出現上述異常
Console.WriteLine(subString1);
Console.WriteLine(subString2);
Console.ReadLine();
}
}
}
程序輸出的結果:
Aquickfoxisjumpingoverthelazydog
Aquickfoxis

substringjs用法

在JS中, 函數聲明: stringObject.substring(start,stop)
start是在原字符串檢索的開始位置,stop是檢索的終止位置,返回結果中不包括stop所指字符.

substringCB用法

substring用途

Returns the substring at the specified location within a String object.

substring用法舉例

strVariable.substring(start, end)
"String Literal".substring(start, end)
用法説明:返回一個字串,其中start是起始的index,end是終止的index,返回的字串包含起始index的字符,但是不包含end的字符。這個是string類下的一個method。

substring用法實例

functionSubstringDemo(){
varss;//Declarevariables.
vars="TheraininSpainfallsmainlyintheplain..";
ss=s.substring(12,17);//Getsubstring.
return(ss);//Returnsubstring.
}

substring資料來源

C++Builder2007幫助文檔(原文是英文的)

substring網上資料

ms-help://borland.bds5/script56/html/9cf9a005-cbe3-42fd-828b-57a39f54224c.htm