我需要将以下 php 函数转换为安卓函数


I need to convert following php function to android function

嗨,我需要以下 php 函数的安卓函数

function BetweenStr($InputString, $StartStr, $EndStr, $StartLoc=0) {
    if (($StartLoc = strpos($InputString, $StartStr, $StartLoc)) === false) { 
        return; 
    }
    $StartLoc += strlen($StartStr);
    if (!$EndStr) { 
        $EndStr = $StartStr; 
    }
    if (!$EndLoc = strpos($InputString, $EndStr, $StartLoc)) { 
        return;
    }
    return substr($InputString, $StartLoc, ($EndLoc-$StartLoc));
}
echo BetweenStr("Cut1 this will be output cut2", 'cut1', 'cut2', 0)
Result will be :"this will be output

这就是我所做的。 但它仍然存在问题

data="Cut1 this will be output cut2";
String substr=data.subString(data.indexOf("cut1"),data.indexOf("cut2"));
public String betweenStr(String input, String open, String close, int startIndex){
    input = input.toLowerCase();
    int start = input.indexOf(open.toLowerCase(), startIndex);
    if(start == -1){
        return null;
    }
    startIndex = start + open.length();
    if(close == null){
        close = open;
    }
    int end = input.indexOf(close.toLowerCase(), startIndex);
    if(end == -1){
        return null;
    }
    return input.substring(startIndex, end);
}
public String betweenStr(String input, String open, String close){
    betweenStr(input, open, close, 0);
}