我有此代码,用于使用映射表将输入文本中的每个字母转换为新文本
Attribute VB_Name = "Module1"
Option Compare Database
Function ReplaceLetters(inputText As String) As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim originalChar As String
Dim mappedChar As String
Dim newText As String
' Open the database and the lookup table
Set db = CurrentDb
Set rs = db.OpenRecordset("LetterMapping", dbOpenSnapshot) ' Lookup table name
newText = inputText
' Loop through each letter in the text
For i = 1 To Len(inputText)
originalChar = Mid(inputText, i, 1) ' Get the character at position i
' Look up the replacement in the table
rs.MoveFirst
Do While Not rs.EOF
If rs!OriginalLetter = originalChar Then
mappedChar = rs!MappedLetter
newText = Left(newText, i - 1) & mappedChar & Mid(newText, i + 1)
Exit Do ' Stop searching once found
End If
rs.MoveNext
Loop
Next i
' Close the recordset
rs.Close
Set rs = Nothing
Set db = Nothing
ReplaceLetters = newText
End Function
代码运行良好,但有些字母会改变一个字母,例如,如果我在输入文本“ÌÍΔ中有这些字母,则在映射字母中只给出一个字母,即第一个字母“ج”