开发者

Converting from Java to VBA [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 years ago.

Improve this question

I need a to create a VBA function that extract a text from a string I wrote this java method

public static String extract(String str) {

    String s = str.substring(str.indexOf("'"),str.lastIndexOf("'"));
    String fg = s.substring(s.indexOf("'")+1, s.indexOf("to")-2);
    String sg = s.substring(s.indexOf("to")+4);

    return sg;

}

which do what I want but in VBA I can't find equivalent to indexOf and lastIndexOf And most importantly how to mimic java substring using indexes o开发者_如何学JAVAf characters without using length to extract as in VBA. could anyone help me.

Thanks in advance.


idx = str.indexOf("'");

// is equivalent of

idx = InStr(str, "'")

and

idx = str.lastIndexOf("'");

// is equivalent of

idx = InStrRev(str, "'")

and

str = str.substring(start, end)

// is equivalent of

str = Mid(str, start, end - start)


The equivalent methods to indexOf and lastIndexOf are inStr and inStrRev.

See http://www.techonthenet.com/excel/formulas/index_vba.php for example.


Equivalent for "substring" is "mid" function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜