7
A
回答
8
如果您只需要ANSI字符,則可以使用StrConv()函數as is done here。
18
馬修回答如何轉換爲ANSI,但如果你希望得到的字節數組仍表示原始Unicode字符串,你乾脆直接給它分配:
Public Sub Main()
Dim b() As Byte
Dim s As String
s = "Whatever"
b = s 'Assign Unicode string to bytes.'
s = b 'Works in reverse, too!'
Debug.Print s
End Sub
這一切就是這麼簡單。你最終得到一個16字節的Byte數組,每個連續的對描述一個Unicode字符。
+1
順便說一句,讓您的意見在VB代碼示例中正確突出顯示,在每個代碼行的末尾添加另一個撇號「 – MarkJ 2009-06-16 08:46:09
-1
' a bit of an example
' had some strings down column G
' nothing in columns "F" or "H" so that current works
' Think about it.. there are many many columns
' so leave blank columns on each side of setsof dats
' then currentregion works ... IFF no blank rows in the data
'
' problem to solve some text was Fred3 John2 Blue3
' others were Bert 3 Green 2 ... which was the require format
' the ASC char 1 ..255 are the odd or even
' numbered bytes if array is 1 based or 0 based
'
Private Sub CommandButton1_Click()
Dim RV$, Ra As Range, Ri&, AL%, WSA() As Byte
Dim Ci%, WS$, LV As Byte
Set Ra = Range("g8").CurrentRegion
For Ri = 1 To Ra.Rows.Count
WSA = CStr(Ra(Ri, 1).value)
AL = UBound(WSA)
LV = WSA(AL - 1) ' last char byte value
If LV > 47 And LV < 58 Then ' 0 to 9
If WSA(AL - 3) <> 32 Then ' no space " "
ReDim Preserve WSA(AL + 2) ' allow 1 more char
WSA(AL - 3) = 32 ' put in space
WSA(AL - 1) = LV ' return char
WS = WSA ' back to a string
Ra(Ri, 1) = WS ' back to the cell
End If
End If
Next Ri
End Sub
' of course the normal VBAcommands Instr len Mid replace &
' would do the job ... but my brain is lazy and needed some exercise
相關問題
- 1. 將字符串數組轉換爲VBA中的新字符串
- 2. 將byte []轉換爲字符串
- 3. 將簡單的json數組轉換爲C#中的字符串數組#
- 4. 如何簡單地將float轉換爲c中的字符串?
- 5. 如何將字符數組中的單個字符轉換爲字符串?
- 6. 如何將字符串數組轉換爲BigQuery中的數組?
- 7. 如何將字符串轉換爲數組中的字符串數組
- 8. 如何將int轉換爲Byte數組?
- 9. 在Java中,如何正確地將byte []轉換爲字符串爲byte []?
- 10. 在DataGridView中將BLOB數據轉換爲簡單的字符串?
- 11. 加密:將字符串數組轉換爲單個字符串
- 12. 如何將字符串數組轉換爲字符串?
- 13. 如何將字符串轉換爲字符串數組String()?
- 14. 如何將非空字符串數組轉換爲字符串?
- 15. 將字符串轉換爲Java中的字符串數組
- 16. 如何將數組的JavaScript字符串轉換爲數組?
- 17. 如何將數組轉換爲字符串數組在android中
- 18. 如何在Excel VBA中將整數轉換爲字符串?
- 19. 如何將字符串中存儲的數據轉換爲字符串數組
- 20. 如何將字符串的元組轉換爲字符串*?
- 21. 如何將字符串數組轉換爲符號數組?
- 22. Python:如何將字符串數組轉換爲數組數組?
- 23. 如何將字節數組轉換爲字符串數組?
- 24. 將數組數組轉換爲angularjs中的字符串數組
- 25. 如何將java byte []轉換爲python字符串?
- 26. 如何將數組內容轉換爲單個字符串C
- 27. 在Java中,如何將InputStream轉換爲字節數組(byte [])?
- 28. 如何將字符和字符串轉換爲字節數組?
- 29. 如何將數組列表轉換爲Javascript中的字符串?
- 30. 如何將字符串轉換爲PHP中的數組file_get_contents?
這兩個答案都很好,但這需要較少的編碼和時間。 – Ubalo 2009-06-15 23:28:41