当前位置:首页 科普知识 substring

substring

发布时间:2023-09-06 00:29:13

substring

substring详细介绍

substring

substring

public String substring(int beginIndex)

返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串索引末尾。在SQLserver数据库中,用于截取字符串的某部分。

substringSQLserver数据库

用于截取字符串的某部分,其基本语法为 select substring(字符串或者列名,起始位置,截取长度) from 表。

例如:

select substring(‘ename’,3,2) from emp;

结果为‘am’。

substringJava

substring简介

例如:

"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 结尾处索引(不包括)。

substring

返回:

指定的子字符串。

抛出:

IndexOutOfBoundsException - 如果 beginIndex 为负,或length大于字符串长度。

substringjavascript示例

<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(stringargs){stringmyString="Aquickfoxisjumpingoverthelazydog";//Substring()在C#中有两个重载函数//分别如下示例stringsubString1=myString.Substring(0);//如果传入参数为一个长整,且大于等于0,//则以这个长整的位置为起始,//截取之后余下所有作为字串.//如若传入值小于0,//系统会抛出ArgumentOutOfRange异常//表明参数范围出界stringsubString2=myString.Substring(0,11);//如果传入了两个长整参数,//前一个为参数子串在原串的起始位置//后一个参数为子串的长度//如不合条件同样出现上述异常Console.WriteLine(subString1);Console.WriteLine(subString2);Console.ReadLine();}}}

程序输出的结果:

AquickfoxisjumpingoverthelazydogAquickfoxis

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)

substring

用法说明:返回一个字串,其中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

温馨提示:
本文【substring】由作者 爱百科 转载提供。 该文观点仅代表作者本人, 自学教育网 信息发布平台,仅提供信息存储空间服务, 若存在侵权问题,请及时联系管理员或作者进行删除。
(c)2008-2025 自学教育网 All Rights Reserved 汕头市灵创科技有限公司
粤ICP备2024240640号-6