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>