def substring(string, start, length=-1):
    """:yaql:substring

    Returns a substring beginning from start index ending with start+end index.

    :signature: string.substring(start, length => -1)
    :receiverArg string: input string
    :argType string: string
    :arg start: index for substring to start with
    :argType start: integer
    :arg length: length of substring. -1 by default, which means end of
        substring to be equal to the end of input string
    :argType length: integer
    :returnType: string

    .. code::

        yaql> "abcd".substring(1)
        "bcd"
        yaql> "abcd".substring(1, 2)
        "bc"
    """
    if length < 0:
        length = len(string)
    if start < 0:
        start += len(string)
    return string[start:start + length]