移除字符串中给定字符串

//移除字符串中所有给定字符串
public class removeAll{
	public static void main(String[] args){
		remove();
	}
	static void remove(){
		String str ="  hello,world"  ;
		System.out.println("移除前的字符串为"+str);
		System.out.println("移除指定的字母0");
		System.out.println("移除l后的字符串为:");
		String str1=str.replaceAll("0", "");//将l移除,其实替换,不过替换的内容为空,如果将引号中给一个内容,就会替换
	    System.out.println("["+str1.trim()+"]");//将str两边的空格删掉
		//我们再次移除一个字母d
		System.out.println("移除一个字母d后的字符串为:");
		String str2=str1.replaceAll("d","");
		System.out.println(str2);
		//再将o字母替换为i like you
		System.out.println("替换后的字符串为:");
		String str3 =str2.replaceAll("o","i like you");
		System.out.println(str3);
	}
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值