http://blog.csdn.net/arui_email/article/details/8800553?locationNum=14
版权声明:本文为博主原创文章,未经博主允许不得转载。
- String strRalationName = "部门信息(ERP系统)—人员信息—父表—生成规则验证";
- //在一段字符中,找出一个字的第几次出现位置
- public int findNumber (String str,String letter,int num){
- int i = 0;
- int m = 0;
- char c = new String(letter).charAt(0);
- char [] ch = str.toCharArray();
- for(int j=0; j<ch.length; j++){
- if(ch[j] == c){
- i++;
- if(i == num){
- m = j;
- break;
- }
- }
- }
- return m;
- }
- <pre class="java" name="code">int m = this.findNumber(strRalationName, "—",2);//获取第二个"—"的位置,m值是16。</pre><pre class="java" name="code">ralationName = strRalationName.substring(0,m);//获取0到m的位置的字符串,此处值是:部门信息(ERP系统)—人员信息。</pre>备注:下标是从0开始的。
- <pre></pre>