/*
 * [TestIndexOf.java]
 *
 * Summary: Demonstrate use of String.indexOf.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.1 2009-04-20 tidy comments.
 */
package com.mindprod.example;

import static java.lang.System.*;

/**
 * Demonstrate use of String.indexOf.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.1 2009-04-20 tidy comments.
 * @since 2009
 */
public final class TestIndexOf
    {
    /**
     * Test harness
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        // use of indexOf
        final String s1 = "ABCDEFGABCDEFG";
        out.println( s1.indexOf( "CD" ) );
        // prints 2, 0-based offset of first CD where found.
        out.println( s1.indexOf( "cd" ) );
        // prints -1, means not found, search is case-sensitive
        out.println( s1.toLowerCase().indexOf( "cd" ) );
        // prints 2,  0-based offset of first cd where found
        out.println( s1.indexOf( "cd".toUpperCase() ) );
        // prints 2,  0-based offset of first cd where found
        out.println( s1.indexOf( "CD", 4/* start looking here, after the first CD */ ) );
        // prints 9, 0-based offset relative to the original string,
        // not relative to the start of the substring
        // use of last indexOf
        out.println( s1.lastIndexOf( "CD" ) );
        // prints 9, 0-based offset of where last CD found.
        out.println( s1.lastIndexOf( "cd" ) );
        // prints -1, means not found, search is case-sensitive
        out.println( s1.toLowerCase().lastIndexOf( "cd" ) );
        // prints 9,  0-based offset of where last cd found
        out.println( s1.lastIndexOf( "cd".toUpperCase() ) );
        // prints 9,  0-based offset of where last cd found
        out.println( s1.lastIndexOf( "CD", 8/* start looking here, prior to last */ ) );
        // prints 2, 0-based offset relative to the original string,
        // not relative to the start of the substring
        out.println( "\u00df" );
        // prints German esset ligature sz single ss bate-like glyph
        out.println( "\u00df".toUpperCase() );
        // prints SS, not SZ, two chars long!
        }
    }