Hi Eros,
so far very good, but I think one little creature slipped the testing.
Try to run this script - it will throw false-positive run time error:
' -- Will trigger run time error, but it should not
MarkSeparator("Monsters (werewolves, dwarfs), are awesome", "!")
Function MarkSeparator( textIn As String, separator As String ) As String
Long i, inBracket
For i = 1 To Len(textIn)
Select Case Mid$(textIn, i, 1)
Case "("
inBracket = TRUE
Iterate For
Case ")"
inBracket = FALSE
Iterate For
Case ","
If inBracket = FALSE Then
Mid$(textIn, i, 1) = separator
End If
End Select
Next
Return textIn
End Function
What is strange is that just reordering the CASEs fixes the problem:
' -- Will run ok
MarkSeparator("Monsters (werewolves, dwarfs), are awesome", "!")
Function MarkSeparator( textIn As String, separator As String ) As String
Long i, inBracket
For i = 1 To Len(textIn)
Select Case Mid$(textIn, i, 1)
Case ","
If inBracket = FALSE Then
Mid$(textIn, i, 1) = separator
End If
Case "("
inBracket = TRUE
Iterate For
Case ")"
inBracket = FALSE
Iterate For
End Select
Next
Return textIn
End Function
Petr
Bookmarks