its not support utf-8? i tested cant find utf-8 strings,any sample or class for can compare or find utf-8 string in another utf-8 string?
Printable View
its not support utf-8? i tested cant find utf-8 strings,any sample or class for can compare or find utf-8 string in another utf-8 string?
UTF8?
All internal VB6 strings are unicode.
The conversion from unicode to an UTF8 byte array is only performed when you save it to disk.
When you get/read an byte array containing utf8 the you need to convert it back to unicode.
There are multiple samples on the forum on how to these conversions
Black_Storm, it would be better you describe your entire use case. Some code from you can explain.
Also, are you sure that you provide a substring in the same utf8 format?
Generally, the class is not intended for utf8.
No, you should keep it as it is.
Black_Storm should use the 2 functions already created by Merri
He also asked for UTF8 controls and much more.
He should deal with his data as normal strings and only convert them when receiving the data.
Code:' StrConvUTF8.bas
Option Explicit
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Sub PutMem4 Lib "msvbvm60" (ByVal Ptr As Long, ByVal Value As Long)
Private Declare Function SysAllocStringLen Lib "oleaut32" (ByVal Ptr As Long, ByVal Length As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, lpUsedDefaultChar As Long) As Long
Public Function StrConvFromUTF8(Text As String) As String
' get length
Dim lngLen As Long, lngPtr As Long: lngLen = LenB(Text)
' has any?
If lngLen Then
' create a BSTR over twice that length
lngPtr = SysAllocStringLen(0, lngLen * 1.25)
' place it in output variable
PutMem4 VarPtr(StrConvFromUTF8), lngPtr
' convert & get output length
lngLen = MultiByteToWideChar(65001, 0, ByVal StrPtr(Text), lngLen, ByVal lngPtr, LenB(StrConvFromUTF8))
' resize the buffer
StrConvFromUTF8 = Left$(StrConvFromUTF8, lngLen)
End If
End Function
Public Function StrConvToUTF8(Text As String) As String
' get length
Dim lngLen As Long, lngPtr As Long: lngLen = LenB(Text)
' has any?
If lngLen Then
' create a BSTR over twice that length
lngPtr = SysAllocStringLen(0, lngLen * 1.25)
' place it in output variable
PutMem4 VarPtr(StrConvToUTF8), lngPtr
' convert & get output length
lngLen = WideCharToMultiByte(65001, 0, ByVal StrPtr(Text), Len(Text), ByVal lngPtr, LenB(StrConvToUTF8), ByVal 0&, ByVal 0&)
' resize the buffer
StrConvToUTF8 = LeftB$(StrConvToUTF8, lngLen)
End If
End Function
Cant Undo for Append
After Append: Some data removeCode:StrEx.Add "remove"
Debug.Print "After Add: " & StrEx.ToString
'or you can use .UndoAppend
StrEx.Undo
Debug.Print "After Undo: " & StrEx.ToString
After Undo: Some data emove
CHANGE TO
Code:Public Function Undo() As Boolean
Undo = True
m_bInRevert = True
Select Case m_LastOp
Case StrEx_LAST_Add
'GetMem2 ByVal StrPtr(vbNullChar), ByVal (m_pMemoryPtr + m_UndoIndexStart * 2)'YOUR CODE
Lenb2 = m_UndoIndexStart * 2 'I CHANGE IT,abcd
Case StrEx_LAST_INSERT
Remove m_UndoIndexStart + 1, m_UndoLength
Case StrEx_LAST_OVERWRITE
Overwrite m_UndoIndexStart + 1, m_UndoText
m_UndoText = vbNullString
Case StrEx_LAST_REMOVE
Insert m_UndoIndexStart + 1, m_UndoText
m_UndoText = vbNullString
Case 0
Undo = False
End Select
m_LastOp = 0 'disallow dual .Undo call
m_bInRevert = False
End Function
Updated.
Quote:
' v2.6
' Fixed .Undo method incorrecly work after .Append / .AppendLine (thanks xiaoyao for pointing me about that back in 2021 :)
'
' v2.5
' Improved speed by replacing some RtlMoveMemory by __vbaCopyBytes
'
' v2.4
' Added check & Err.raise to all methods to ensure user doesn't accidentally call this class within Forms' Terminate event.
Hello @Dragokas,
I hope this message finds you well.
I was wondering if it would be possible to update your code to support both 32-bit and 64-bit
Hi, phoronex.
Do you mean TwinBasic support?
Thanks for your quick reply
I mean The awesome (clsStringBuilder)
I'm using ms Access VBA
Sorry, I have a very limited time due to the lack of electricity and issues with my UPS device and a bunch of other social problems related to the war.
Also, I didn't touch VBA x64 for a while. Maybe somebody else may pick up the project.
Thanks a lot,
I wish all the best for you.
phoronex, try to rewrite this class for the needs of x64 yourself, it's not that difficult