Converting from Java to VBA [closed]
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 questionI 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.
精彩评论