码迷,mamicode.com
首页 > 编程语言 > 详细

Java 实例 - 删除字符串中的一个字符

时间:2018-03-03 13:59:38      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:之间   字符   ack   image   sub   ati   int   div   static   

package string;

public class deleteString {
    /**
     * 删除字符串
     * @param args
     */
    public static void main(String[] args) {
        String str = "helloo,this is my third blog";
        String str1 = removeCharAt(str, 5);
        System.out.println(str1);

    }

    public static String removeCharAt(String s, int pos) {

        return s.substring(0, pos) + s.substring(pos + 1);// 使用substring()方法截取0-pos之间的字符串+pos之后的字符串,相当于将要把要删除的字符串删除
    }
}

输出结果技术分享图片

 

Java 实例 - 删除字符串中的一个字符

标签:之间   字符   ack   image   sub   ati   int   div   static   

原文地址:https://www.cnblogs.com/zhuxiaopang/p/8496254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!