zoukankan      html  css  js  c++  java
  • java截取一个字符串正数或倒数某个特定字符前后的内容

    取出正数第二个“.”后面的内容

    public class TestCode {
        public static void main(String[] args) {
            String str ="232ljsfsf.sdfl23.ljsdfsdfsdfss.23423.sdfsdfsfd";
            //获得第一个点的位置
            int index=str.indexOf(".");
            System.out.println(index);
            //根据第一个点的位置 获得第二个点的位置
            index=str.indexOf(".", index+1);
            //根据第二个点的位置,截取 字符串。得到结果 result
            String result=str.substring(index);
            //输出结果
            System.out.println(result);
        }
    
    }

    取出倒数第三个“-”前面的内容

    public class subString {
        public static void main(String[] args) {
            String b = "/dota-2/talent/arc-warden-20-2-38";
            String subStringB = b.substring(b.lastIndexOf("/")+1);
            int index=subStringB.lastIndexOf("-");
            index=subStringB.lastIndexOf("-", index-1);
            index=subStringB.lastIndexOf("-",index-1);
            System.out.println(subStringB.substring(0,index));
        }
    
    }
  • 相关阅读:
    RAID中条带的概念
    关于几个与IO相关的重要概念
    分布式调度
    ajax
    choices参数
    1.Python实现字符串反转的几种方法
    django web框架
    CRM总结
    Python面试重点(web篇)
    day02-网编并发数据库
  • 原文地址:https://www.cnblogs.com/Java-Starter/p/8343769.html
Copyright © 2011-2022 走看看