简体   繁体   中英

Which function in Java is like the LIKE Operator in Lotusscript

is there a function for Java that works like the LIKE operator in lotusscript ? Or is there something I can easily configure, so it works the same?

Or do i have to build it my own?

Thanks in advance

No there isn't. The closest thing you can have on Java will be regex most likely the matches method from the class String.

But it will require you to use regular expression instead of wildcards as the lotusscript function you mentioned.

Here is a reference to a Regular Expressions

As for this example on the doc you show from lotusscript:

  • two-digit numbers from 1 to 100 that end in 3 and don't begin with 2

     For x = 1 To 100 If CStr(x) Like "[!2]3" Then Print x Next x 

    The equivalent in java would be:

     public static void main(String[] args) { for (int i=1;i<=100;i++){ if ( String.valueOf(i).matches("[^2]{1}3") ){ System.out.println( i ); } } } 

    The output would be: 13 33 43 53 63 73 83 93

  • You have to find out the regular expression in java. Here is the link.

    http://www.vogella.com/tutorials/JavaRegularExpressions/article.html

    Below tutorial have some working examples as well.

    You can use java.util.regex.Pattern and java.util.regex.Matcher , above link has those examples as well.

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM