def findTrueWidth(string):
    """
    Find the length of a byte string without trailing zeros. Useful for optimizing string matching functions.

    Parameters
    ----------
    string : a byte string as an array of int8
        A byte string as an array of int8

    Returns
    -------
    int
        Number of bytes in string.

    Examples
    --------
    >>> a = np.chararray(1, itemsize=5)
    >>> a[0] = b'abc'
    >>> findTrueWidth(np.frombuffer(a,dtype=np.int8))
    3
    """
    # Find the length of a byte string (without the trailing zeros)
    # the input must be dtype=np.int8, use np.frombuffer()
    width = string.shape[0]
    trailing = 0
    for i in reversed(range(width)):
        if string[i]:
            break
        else:
            trailing+=1
    return width-trailing