Page last modified 13:17, 14 Aug 2015 by juhako

.lastIndexOf() Redirected from Guide for writing business rules with OCL/Available methods for OCL base types/.lastIndexOf()

    Description of the method

     

    Description: .lastIndexOf() method returns the last position of string or character from a string. The string or character to be searched for is given as parameter. If nothign is found "-1" will be returned.

    Check .indexOf() if you are trying to find the first occurrence of string or character.
    Available for: string
    Parameters: string
    Return type: integer

    Example1

     

    Context: HeaderType1
    OCL: self.Id.lastIndexOf('content') = 9
    Description: The example checks if last string 'content' is found starting from the position 1 of the value of the <Id> element. First position of a string is 0.

     

    The XML snippet below would pass this check as the last occurrence of string "content" starts from index 9. First occurrence is starting from index 1.

    <Id>1content2content</Id>

    The other snippet below however would not pass this check as the string "content" starts from index 0.

    <Id>content</Id>

     

    Example2

     

    Context: HeaderType1
    OCL: self.Id.lastIndexOf('a') = -1
    Description: The rule here checks if character a is found from the value of element <Id>. The rule passes if character a is not found as then the lastIndexOf method returns value -1.

     

    The XML snippet below would pass this check as the string "value" starts from index 1 (first index is 0).

    <Id>bbb</Id>

    The other snippet below however would not pass this check as the string "value" starts from index 0.

    <Id>aaa</Id>

     

    Attached you can find example schema and files which you can use for testing.

    Menu