如何返回上一个之后的下一个indexOf? [英] How to return the next indexOf after a previous?

查看:195
本文介绍了如何返回上一个之后的下一个indexOf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

str = "(a+b)*(c+d)*(e+f)"
str.indexOf("(") = 0
str.lastIndexOf("(") = 12

如何在第二个括号中获取索引?
(c + d)< - this

How to get the index in second bracket? (c+d) <- this

推荐答案

试试这个:

 String word = "(a+b)*(c+d)*(e+f)";
 String c = "(";
  for (int index = word.indexOf(c);index >= 0; index = word.indexOf(c, index + 1)) {
       System.out.println(index);//////here you will get all the index of  "("
    }

这篇关于如何返回上一个之后的下一个indexOf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆