Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
StrTran() case insensitive
Message
De
07/07/2010 21:25:28
 
 
À
07/07/2010 16:35:57
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01471738
Message ID:
01471774
Vues:
42
>I am using this for a StrTran() function followed by a similar function but in case insensitivity:
>
>
>        ' Equivalent of VFP StrTran()
>        ' expC1 String
>        ' expC2 Search for specific character
>        ' expC3 Replace
>        Public Function StrTran(ByVal tcSearchIn As String, ByVal tcSearchFor As String, _
>         ByVal tcReplace As String) As String
>            Dim loStringBuilder As StringBuilder = New StringBuilder(tcSearchIn)
>            Return loStringBuilder.Replace(tcSearchFor, tcReplace).ToString()
>        End Function
>
>        ' Equivalent of VFP StrTran() with case insensitive
>        ' expC1 String
>        ' expC2 Search for specific character
>        ' expC3 Replace
>        Public Function StrTranCaseInsensitive(ByVal tcSearchIn As String, ByVal tcSearchFor As String, _
>         ByVal tcReplace As String) As String
>            Dim lnLength As Integer = tcSearchIn.Length
>            Dim lnLengthSearchFor As Integer = tcSearchFor.Length
>            Dim lnLocation As Integer = 0
>            Dim loStringBuilder As New StringBuilder(lnLength)
>
>            ' Check inputs
>            If lnLength = 0 Or lnLengthSearchFor = 0 Or lnLengthSearchFor > lnLength Then
>                Return tcSearchIn
>            End If
>
>            While lnLocation + lnLengthSearchFor <= lnLength
>
>                If String.Compare(tcSearchIn, lnLocation, tcSearchFor, 0, lnLengthSearchFor, True) = 0 Then
>
>                    ' Add the replaced string
>                    loStringBuilder.Append(tcReplace)
>
>                    lnLocation = lnLocation + lnLengthSearchFor
>                Else
>
>                    ' Advance one character
>                    loStringBuilder.Append(tcSearchIn, lnLocation, 1)
>                    lnLocation = lnLocation + 1
>
>                End If
>
>            End While
>
>            ' Append remaining characters
>            loStringBuilder.Append(tcSearchIn, lnLocation, lnLength - lnLocation)
>
>            Return loStringBuilder.ToString()
>        End Function
>
>
>Would it there be a way to simplify the second method as we did for the first one?

Is this one case-sensitive? (not tested - i don't use vb.net) - might be the long way around....

http://www.rcsbox.com/vbcodestore/thecode/00000029.html

oops...the loop makes it definitely not as efficient as regex... Never mind - bad example ...(also too close to what you were doing) (that didn't come out right)
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform