java.lang.String.startsWith 和 endsWith的区别 用法
来源:互联网 发布:数据看板 编辑:程序博客网 时间:2024/04/29 03:52
public class StringDemo{
public static void main(String args[]){
String s1="this is my original string";
String sd="original";
if (s1.startsWith(sd))
//startsWith()方法判断字符串s1是否从字符串sd开始
s1=s1.substring(sd.length());
else
if(s1.endsWith(sd))
//endWith()方法判断字符串s1是否从字符串sd结尾
s1=s1.substring(0,s1.length()-sd.length());
else
{
int index=s1.indexOf(sd);
//indexOf()搜索字符或子字符串首次出现,这里的index等于11
if(index!=-1)
{
String s2=s1.substring(0,index);
//从字符串s1的首字符开始,取index个字符
String s3=s1.substring(index+sd.length());
//取字符串s1的第19个字符后面的字符串
s1=s2+s3;
}
else
System.out.println("string /""+sd+"/" not found");
}
System.out.println(s1);
//lastIndexOf获取最后的一个索引
}
}
- java.lang.String.startsWith 和 endsWith的区别 用法
- java startsWith和endsWith的用法
- java startsWith和endsWith的用法
- java startsWith和endsWith的用法
- java startsWith和endsWith的用法
- String的endsWith/startsWith
- java中startsWith与endsWith的用法
- startsWith(),endsWith()的作用和用法
- Python中startswith和endswith的用法
- line.startsWith(tem)-----startsWith(),endsWith()的作用和用法
- java endsWith()和startsWith方法的解释
- java startsWith和endsWith详解
- Python的startswith和endswith
- Python的startswith和endswith
- Python的startswith和endswith
- Python的 startswith 和endswith
- Android关于String数据的startsWith()和endsWith()函数操作
- python中startswith和endswith的使用
- CListCtrl::GetItemState
- Linux Shell编程case语句
- javascript深入理解js闭包
- Node.js用fs.renameSync报cross-device link not permitted错
- 内核并发控制---完成量 (来自网易)
- java.lang.String.startsWith 和 endsWith的区别 用法
- 智力题——17.玻璃搅拌机
- User Story Q&A
- VC++ 读取二进制文件以及写入文件简单示例:
- 回调函数的概念及其使用
- 为什么需要使用MQ?
- linux 中解析命令行参数
- LeetCode: Spiral Matrix
- 内核并发控制---互斥量(来自网易)