How to find the position of a format change on a text line


I come to you to help me find a solution to find the exact position where a format or attribute change occurs on a line of text.
I did this by looping through the characters in the line and using getFormatField for each character, but it takes a long time if the line of text is too long.
Can you think of a faster solution?
How  can we know the position of a field return by getFormatField ?
Thank you.

Best regards.