intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Các hàm UNICODE thông dụng

Chia sẻ: Abcdef_45 Abcdef_45 | Ngày: | Loại File: PDF | Số trang:6

43
lượt xem
3
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Đổi chữ thường thành chữ hoa: Function UpperUniChar(Ch) As String ' Return the Uppercase for a given vowel or dd Dim Pos ' Position of character in Unicode vowel list ' Locate the character in list of Unicode vowels Pos = InStr(UVowels, Ch) If (Pos 67) Then UpperUniChar = Ch ' It's already uppercase - leave it alone ElseIf (Pos 0) Then ' It's a Lowercase Unicode Vowel - so get the corresponding Uppercase vowel in the list UpperUniChar = Mid(UVowels, Pos + 67, 1) Else ' It's just a normal ANSI character UpperUniChar = UCase(Ch) End If...

Chủ đề:
Lưu

Nội dung Text: Các hàm UNICODE thông dụng

  1. Các hàm UNICODE thông d ụng Đổi chữ thường thành chữ hoa: Function UpperUniChar(Ch) As String ' Return the Uppercase for a given vowel or dd Dim Pos ' Position of character in Unicode vowel list ' Locate the character in list of Unicode vowels Pos = InStr(UVowels, Ch) If (Pos > 67) Then UpperUniChar = Ch ' It's already uppercase - leave it alone ElseIf (Pos > 0) Then ' It's a Lowercase Unicode Vowel - so get the corresponding Uppercase vowel in the list UpperUniChar = Mid(UVowels, Pos + 67, 1) Else ' It's just a normal ANSI character UpperUniChar = UCase(Ch) End If End Function
  2. Đọc Text UNICODE từ file Public Function ReadTextFile(FileName) As String ' Write a Unicode String to UTF-16LE Text file ' Remember to Project | References "Microsoft Scripting Runtime" to support ' FileSystemObject & TextStream Dim Fs As FileSystemObject Dim TS As TextStream ' Create a FileSystem Object Set Fs = CreateObject("Scripting.FileSystemObject") ' Open TextStream for Input. ' TriStateTrue means Read Unicode UTF-16LE Set TS = Fs.OpenTextFile(FileName, ForReading, False, TristateTrue) ReadTextFile = TS.ReadAll ' Read the whole content of the text file in one stroke TS.Close ' Close the Text Stream Set Fs = Nothing ' Dispose FileSystem Object
  3. End Function Viết UNICODE text ra file Public Sub WriteTextFile(FileName, StrOutText) ' Read a Unicode String from UTF-16LE Text file ' Remember to Project | References "Microsoft Scripting Runtime" to support ' FileSystemObject & TextStream Dim Fs As FileSystemObject Dim TS As TextStream ' Create a FileSystem Object Set Fs = CreateObject("Scripting.FileSystemObject") ' Open TextStream for Output, create file if necesssary ' TriStateTrue means Write Unicode UTF-16LE Set TS = Fs.OpenTextFile(File Name, ForWriting, True, TristateTrue) TS.Write StrOutText ' Write the whole StrOutText string in one stroke TS.Close ' Close the Text Stream
  4. Set Fs = Nothing ' Dispose FileSystem Object End Sub Cách gọn và tiện nhất để đọc và viết UTF-8 text files là dùng m ột VB6 Class tên clsUnicodeText d ựa vào MS DOM (Document Object Model) và XML như sau: Dim MyUnicodeText As clsUnicodeText Set MyUnicodeText = New clsUnicodeText ' Read Unicode Text from file txtFileName and display in TextBox1 TextBox1.Text = MyUnicodeText.ReadUnicode(txtFileName) Listing của Class clsUnicodeText nh ư sau: Option Explicit Private mDOMTextFile As DOMDocument Private mXMLPath As String
  5. Public Function ReadUnicode(TXMLPat h) Dim objTextFileRoot As IXMLDOMElement Set mDOMTextFile = New DOMDocument mXMLPath = TXMLPath mDOMTextFile.Load mXMLPath 'start at the root element of the XML Set objTextFileRoot = mDOMTextFile.documentElement ReadUnicode = objTextFileRoot. nodeTypedValue End Function Public Sub WriteUnicode(OutText, Optional TXMLPath) Dim tDOMNode As IXMLDOMElement ' Temporary Node for DOM If IsMissing(TXMLPath) Then ' Save the information on the screen by creating a new element and add its children to the DOM object mDOMTextFile.documentElement.Text = OutText ' Update the XML file mDOMTextFile.save mXMLPath Else Set mDOMTextFile = New DOMDocument
  6. ' Create a Node called "Text" in DOM Set tDOMNode = mDOMTextFile.createElement("Text") ' Make it the Root Node mDOMTextFile.appendChild tDOMNode ' Assign Output Text to Root Node mDOMTextFile.documentElement.Text = OutText ' Update the XML file mDOMTextFile.save TXMLPath End If End Sub Nguồn: Vovisoft {/tab}
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2