title: optimal code for detecting formatting differences?
body: <p>I need to compare two formatted strings. The text in the two of them is the same, only the formatting differs, meaning that some words are bold. The code should tell me if the location of the bold substrings are different e.g. the strings are formatted differently.
  So far I tried a char-to-char approach, but it is far too slow. </p>
  
  <p>It's a plain legal current text in MS Word, with cca 10-500 chars per string. Two people independently formatted the strings.</p>
  
  <p>my code so far:</p>
  
  <pre><code>Function collectBold(r As Range) As String
  Dim chpos As Integer
  Dim ch As Variant
  Dim str, strTemp As String
  chpos = 1
  Do
  If r.Characters(chpos).Font.Bold Then
      Do
          Dim boold As Boolean
          strTemp = strTemp + r.Characters(chpos)
          chpos = chpos + 1
          If (chpos &lt; r.Characters.Count) Then boold = r.Characters(chpos).Font.Bold
      Loop While (boold And chpos &lt; r.Characters.Count)
     str = str + Trim(strTemp) + "/"
     strTemp = ""
  Else: chpos = chpos + 1
  End If
  Loop While (chpos &lt; r.Characters.Count)
  collectBold = str
  End Function
  </code></pre>
  
  <p>This code collect all bold substrings (strTemp) and merges them into one string (str), separating them with "/". The function runs for both strings to compare, and then checks if the outputs are the same.</p>