我之前发布了这个,得到了一些迄今为止对我没用的答案。因此,我将发布部分代码,以便您可以看到我在说什么。突出显示的部分是我从另一篇文章中提取的内容,它现在不适合我。我正在使用visual studio 2008,该程序是用Basic编写的。我从网上取下了大部分这个程序并开始调整它以满足我的需求,如果你能帮助我欣赏它!谢谢! 如果您熟悉阿拉伯语,您将理解这些字母,如果不熟悉,只需使用A和B作为变量。
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If CheckBox1.Checked = True Then
TextBox2.Text = convert(TextBox1.Text)
End If
End Sub
Private Sub OpenToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim AllText, LineOfText As String
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
Try '
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1) '
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
Loop
TextBox1.Text = AllText
TextBox1.Select(1, 0)
TextBox1.Enabled = True
Catch
MsgBox("Error opening file.")
Finally
FileClose(1)
End Try
End If
End Sub
Public Function convert(ByVal gaby As String)
Try
gaby = Replace(gaby.ToLower, "a", "ا")
gaby = Replace(gaby.ToLower, "ab", "اب")
gaby = Replace(gaby.ToLower, "ac", "اث")
gaby = Replace(gaby.ToLower, "b", "ب")
gaby = Replace(gaby.ToLower, "t", "ت")
gaby = Replace(gaby.ToLower, "c", "ث")
gaby = Replace(gaby.ToLower, "j", "ج")
gaby = Replace(gaby.ToLower, "h", "ح")
gaby = Replace(gaby.ToLower, "o", "خ")
gaby = Replace(gaby.ToLower, "d", "د")
gaby = Replace(gaby.ToLower, "z", "ذ")
gaby = Replace(gaby.ToLower, "r", "ر")
gaby = Replace(gaby, Chr(59), "ز")
gaby = Replace(gaby.ToLower, "s", "س")
gaby = Replace(gaby.ToLower, Chr(58), "ش")
gaby = Replace(gaby.ToLower, "x", "ص")
gaby = Replace(gaby.ToLower, "v", "ض")
gaby = Replace(gaby.ToLower, "u", "ط")
gaby = Replace(gaby.ToLower, "y", "ظ")
gaby = Replace(gaby.ToLower, """", "ع")
gaby = Replace(gaby.ToLower, "g", "غ")
gaby = Replace(gaby.ToLower, "f", "ف")
gaby = Replace(gaby.ToLower, "q", "ق")
gaby = Replace(gaby.ToLower, "k", "ك")
gaby = Replace(gaby.ToLower, "l", "ل")
gaby = Replace(gaby.ToLower, "m", "م")
gaby = Replace(gaby.ToLower, "n", "ن")
***gaby = Replace(gaby.ToLower, Chr(63), "ه", 1, Len(gaby) - 1)
If Microsoft.VisualBasic.Right(gaby, 1) = Chr(63) Then
Mid$(gaby, Len(gaby), 1) = "ة"
End If***
gaby = Replace(gaby.ToLower, "w", "و")
gaby = Replace(gaby.ToLower, "i", "ي")
gaby = Replace(gaby.ToLower, "e", "ء")
gaby = Replace(gaby.ToLower, "", "")
Catch
MsgBox("error converting")
End Try
Return gaby
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = convert(TextBox1.Text)
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
MsgBox("سلام converter copyrights 2009" & vbCrLf & "تستمتع" & vbCrLf & "" & vbCrLf & "Hope this helps!!!")
End Sub
Private Sub AutoConvertToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoConvertToolStripMenuItem.Click
If CheckBox1.Checked = True Then
CheckBox1.Checked = False
Else : CheckBox1.Checked = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = String.Empty
TextBox2.Text = String.Empty
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, TextBox2.Text)
FileClose(1)
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
End Class
答案 0 :(得分:1)
Replace方法为要替换的部分采用字符串,而不仅仅是字符。怎么样的
gaby = Replace(gaby.ToLower, "1" + Chr(63), "ة" + Chr(63))
gaby = Replace(gaby.ToLower, "1", "ه")
当然,替换的顺序很重要。在替换剩余的1之前,将删除Chr(63)后面的1s。
(我的结果字符串中的顺序是否错误。结果应该是从右到左。不应该吗?)
答案 1 :(得分:0)
正如我在other post中读到的那样,如果字符串在字符串的末尾,则字符会更改为其他值。您可以使用二维数组来存储原始的阿拉伯字符和两个不同的拉丁字符;然后,对于阿拉伯语字符串中的每个字符,在数组中查找它并将其更改为第一个等效的拉丁字符;如果它是原始字符串中的最后一个字符,则将其更改为第二个拉丁字符。