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

.indexOf()

    Description of the method

     

    Description:

    .indexOf() method returns first position of string or character from a string. The string or character to be searched for is given as parameter. If nothing is found "-1" will be returned.

    Check .lastIndexOf() if you are trying to search the last occurrence of string or character.

    Available for: string
    Parameters: string
    Return type: integer

    Example1

     

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

     

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

    <Id>1content2content</Id>

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

    <Id>content2content</Id>

     

    Example2

     

    Context: HeaderType1
    OCL: self.Id.indexOf('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