首页 > 作文

java的substring方法(substring截取字符串用法)

更新时间:2023-04-05 04:05:03 阅读: 评论:0

string类的常用方法

1、常用方法系列之一

int length():返回字符串的长度: return value.length;boolean impty():判断是否是空字符串:return value.length == 0;string tolowerca():使用默认语言环境的规则将此 string 中的所有字符都转换为小写。string toupperca():使用默认语言环境的规则将此 string 中的所有字符都转换为大写。string trim():返回字符串的副本,忽略前导空白和尾部空白。boolean equals(object obj):比较字符串的内容boolean equalsignoreca(string anotherstring):与equals方法类似,忽略大小写string concat(string str):将指定字符串连接到此字符串的结尾。 等价于用“+”

2、string类和字符相关操作

char charat(int index): 返回某索引处的字符return value[index];char[] tochararray():将此字符串转换为一个新的字符数组string(char[] value):分配一个新的 string,使其表示字符数组参数中当前包含的字符序列。string(char[] value, int offt, int count):分配一个新的 string,它包含取自字符数组参数一个子数组的字符。

3、string类字节与字符串操作方法

编码:把字符–>字节

byte[] getbytes():使用平台的默认字符集将此 string 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。byte[] getbytes(chart chart) :使用给定的 chart 将此 string 编码到 byte 序列,并将结果存储到新的 byte 数组。byte[] getbytes(string chartname) :使用指定的字符集将此 string 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。

解码:把字节–>字符

string(byte[] bytes) :通过使用平台的默认字符集解码指定的 byte 数组,构造一个新的 string。string(byte[] bytes, chart chart):通过使用指定的 chart 解码指定的 byte 数组,构造一个新的 string。string(byte[] bytes, int offt, int length) :通过使用平台的默认字符集解码指定的 byte 子数组,构造一个新的 string。string(byte[] bytes, int offt, int length, chart chart):通过使用指定的 chart 解码指定的 byte 子数组,构造一个新的 string。string(byte[] bytes, int offt, int length, string chartname):通过使用指定的字符集解码指定的 byte 子数组,构造一个新的 string。string(byte[] bytes, string chartname):通过使用指定的 char第二英语怎么读t 解码指定的 byte 数组,构造一个新的 string。

4、string类判断是否以指定内容开头或结尾

boolean endswith(string suffix):测试此字符串是否以指定的后缀结束。boolean startswith(string prefix):测试此字符串是否以指定的前缀开始。boolean startswith(string prefix, int tofft):测试此字符串从指定索引开始的子字符串是否以指定前缀开始。

5、string类字符串查找操作

boolean contains(charquence s):当且仅当此字符串包含指定的 char 值序列时,返回 true。int indexof(int ch):返回指定字符在此字符串中第一次出现处的索引。int indexof(i王妃 歌词nt ch, int fromindex):返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜ktv歌曲索。int indexof(string str):返回指定子字符串在此字符串中第一次出现处的索引。int indexof(string str, int fromindex):返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。int lastindexof(int ch):返回指定字符在此字符串中最后一次出现处的索引。int lastindexof(int ch, int fromindex):返回指定字符在此字符串中最后一次出现处的索引,从指定的索引处开始进行反向搜索。int lastindexof(string str):返回指定子字符串在此字符串中最右边出现处的索引。int lastindexof(string str, int fromindex):返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。

indexof和lasti骨质增生怎么治疗呀ndexof方法如果未找到都是返回-1

6、string类字符串截取操作

string substring(int beginindex)

返回一个新的字符串,它是此字符串的从beginindex开始截取到最后的一个子字符串。

string substring(int beginindex, int endindex)

返回一个新字符串,它是此字符串从beginindex开始截取到endindex(不包含)的一个子字符串。

7、string类是否匹配正则

boolean matches(string regex):告知此字符串是否匹配给定的正则表达式。

8、string类替换操作

string replace(char oldchar, char newchar):

返回一个新的字符串,它是通过用 newchar 替换此字符串中出现的所有 oldchar 得到的。

string replace(charquence target, charquence replacement):

使用指定的字面值替换序列替伤感qq个性签名换此字符串所有匹配字面值目标序列的子字符串。

string replaceall(string regex, string replacement):

使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。

string replacefirst(string regex, string replacement):

使用给定的 replacement 替换此字符串匹配给定的正则表达式的第一个子字符串。

9、string类字符串拆分操作

string[] split(string regex):根据给定正则表达式的匹配拆分此字符串。string[] split(string regex, int limit):根据匹配给定的正则表达式来拆分此字符串,最多不超过limit个,如果超过了,剩下的全部都放到最后一个元素中。

本文发布于:2023-04-05 04:05:02,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/f38a08f5c0ad17c859ec93c8fef99399.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:java的substring方法(substring截取字符串用法).doc

本文 PDF 下载地址:java的substring方法(substring截取字符串用法).pdf

标签:字符串   数组   字符   索引
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图