Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MacOS Silverlight bugs
I've come across a problem that happens on some and not all MACs - approx 5% of our MAC users. It does not appear to have anything to do with 32/64bit or OS version or Hardware type.
 
It is to do with a custom search and replace routine to fix CR/LF in a string that is up to 2,000 characters long.
 
Here's the routine:
Public Function FixCRLF(ByVal InputString As String) As String
        Return FixCR(FixLF(InputString))
    End Function
 
    Public Function FixCR(ByVal InputString As String) As String
 
        If InputString Is Nothing Then Return Nothing
 
        Dim result As New StringBuilder()
        Dim oldValue As String = vbCr
        Dim lenOldValue As Integer = oldValue.Length
        Dim curPosition As Integer = 0
 
        Dim idxNext As Integer = InputString.IndexOf(oldValue)
        While idxNext >= 0
            result.Append(InputString, curPosition, idxNext - curPosition)
            If Not InputString.IndexOf(vbLf, idxNext) = idxNext + 1 Then
                result.Append(vbCrLf)
            Else
                result.Append(vbCr)
            End If
            curPosition = idxNext + 1
            idxNext = InputString.IndexOf(oldValue, curPosition)
        End While
 
        result.Append(InputString, curPosition, InputString.Length - curPosition)
        Return result.ToString()
 
    End Function
 
    Public Function FixLF(ByVal InputString As String) As String
 
        If InputString Is Nothing Then Return Nothing
 
        Dim result As New StringBuilder()
        Dim oldValue As String = vbLf
        Dim lenOldValue As Integer = oldValue.Length
        Dim curPosition As Integer = 0
 
        Dim idxNext As Integer = InputString.IndexOf(oldValue)
        While idxNext >= 0
            result.Append(InputString, curPosition, idxNext - curPosition)
            Dim idxBack As Integer = idxNext - 1
            If Not InputString.IndexOf(vbCr, idxBack) = idxBack Then
                result.Append(vbCrLf)
            Else
                result.Append(vbLf)
            End If
            curPosition = idxNext + 1
            idxNext = InputString.IndexOf(oldValue, curPosition)
        End While
 
        result.Append(InputString, curPosition, InputString.Length - curPosition)
        Return result.ToString()
 
    End Function
 
We see the CPU spike to 100% for approx 5 to 25 minutes showing the pinwheel (busy) cursor then eventually return.
 
Windows SL5 runtimes do not experience this problem.
 
Is this a runtime bug or an error in my coding?
 
Graeme
Posted 17-Apr-12 21:09pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100