java 字符串相减(很简单的一个方法)

2016-02-19 09:09 4 1 收藏

今天图老师小编要向大家分享个java 字符串相减(很简单的一个方法)教程,过程简单易学,相信聪明的你一定能轻松get!

【 tulaoshi.com - 编程语言 】

有个比较简单的方法:
代码如下:

str1="abcd";
str2="cd";
str3=str1.replaceAll(str2,"");
//str3="ab"

来源:https://www.tulaoshi.com/n/20160219/1589711.html

延伸阅读
题目:定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。如把字符串abcdef左旋转2位得到字符串cdefab。请实现字符串左旋转的函数。要求时间对长度为n的字符串操作的复杂度为O(n),辅助内存为O(1)。 分析:如果不考虑时间和空间复杂度的限制,最简单的方法莫过于把这道题看成是把字符串分成前后两部分,通过旋转操作把这...
标签: PHP
  一个可以删除字符串中HTML标记的PHP函数 作者:limote 当访客留言和发帖时,我们并不希望访客在留言和帖子中使用HTML标记,所以在访客提交留言和帖子时我门得把HTML标记删除,下面的函数就是实现此功能的函数 <? function delete_htm($scr) { for($i=0;$i<strlen($scr);$i++) { if(substr($scr,$i,1)==&q...
(1).String 和StringBuffer对象的创建! (2).String类的常用方法:       length(), charAt(), getchars(), equals(),starsWith(), endsWith(), indexOf(), laseIndex(), substring(),contact()       replace(), valueOf(). (3).StringBuffer类的常用方法: &nbs...
标签: Web开发
代码如下: /** * 截取字符串 len为字节长度 * @param str * @param len * @return * @throws UnsupportedEncodingException */ public static String getLimitLengthString( String str,int len){ try{ int counterOfDoubleByte = 0; byte[] b = str.getBytes("gb2312"); if(b.length = len) return str; for(int i = 0; i len...
方法1:采用String的split,验证代码如下: import java.util.Arrays; public class TestSplit {  public static void main(String[] args) {   String orignString = new String("5,8,7,4,3,9,1");   String[] testString = orignString.split(",");   int[] test = { 0, 0, 0, 0, 0, 0, ...

经验教程

314

收藏

17
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部