VB and VBA Users Source Code: Reverse a string using a byte array
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Reverse a string using a byte array
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, March 30, 2001
Hits:
729
Category:
Visual Basic General
Article:
The following function demonstrates how to effeciently reverse a string using a byte array. 'Purpose : Reverses a string 'Inputs : sValue The string to reverse. 'Outputs : The reversed of the input string variable sValue. 'Author : Andrew Baker 'Date : 25/03/2000 'Notes : The data is copied into a byte array for speed, then Public Function StringReverse(sValue As String) As String Dim lThisByte As Long, lUBound As Long Dim abyteOriginal() As Byte, abyteReversed() As Byte If Len(sValue) Then 'Copy string into byte array abyteOriginal = sValue lUBound = UBound(abyteOriginal) 'Size output array ReDim abyteReversed(lUBound) 'Loop over array swaping Unicode blocks over For lThisByte = 0 To lUBound Step 2 abyteReversed(lThisByte) = abyteOriginal(lUBound - lThisByte - 1) abyteReversed(lThisByte + 1) = abyteOriginal(lUBound - lThisByte) Next 'Return result StringReverse = abyteReversed End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder