在甲骨文中:
情况1:
SELECT INSTR('Viveok Srinivoasamoorthy','o',15,1) FROM DUAL;
输出:19
案例2:SELECT INSTR('Viveok Srinivoasamoorthy','o',15,2) FROM DUAL; 输出:20
同样,我需要开发一个具有 4 个参数(字符串、子字符串、start_position 和 nthoccurrence)的 java 程序来实现。
这是我尝试过的代码,但在下面的代码中我找不到第 n 次出现:
public static int nthoccur(String str1,String str2,int occurs )
{
int f_occurance=0;
f_occurance=str1.indexOf(str2, occurs-1)+1;
System.out.println("f_occurance Value------*** "+f_occurance);
return f_occurance;
}
public static void main(String args[])
{
int resultinst=nthoccur("Viveok Srinivoasamoorthy","o",15);
System.out.println(resultinst);
}
输出:
f_occurance Value------*** 19
19
现在我想使用java程序从字符串的第15个位置找到第二个出现的“o”。如何使用 Java 程序实现案例 2?