我试图在调试窗口中按顺序显示波斯字母。一旦到达最后一个字母,后续字母将乘以它们所在的组。因此,例如,如果我想为字母“A”显示 alef (ا) - 波斯语,我将从索引 1 开始. 如果我达到 33 的索引(波斯有 32 个字母),它应该显示 (اا)。
下面的代码适用于拉丁字母(例如“abcdefj...”),但对于波斯语/阿拉伯语,我有两个问题。
- 它给出的计数是 33 而不是 32 - 即在字母“ه”之后产生一个空白字符。我怀疑是这个,但不知道如何解释。
对于需要加倍的字符,例如“ش ش”(没有空格),它显示为“شش”。
Sub Main() Dim t As New PersianAlphabet For i = 1 To 50 Debug.WriteLine(t.NextLetter()) Next End Sub Public Class PersianAlphabet Private charArray As String Private charCount As Integer Private CurrentNumber As Integer = 0 Sub New() 'Dim charArray1() = {"ا", "ب", "پ", "ت", "ث", "ج", "چ", "ح", "خ", "د", "ذ", "ر", "ز", "ژ", "س", "ش", "ص", "ض", "ط", "ظ", "ع", "غ", "ف", "ق", "ک", "گ", "ل", "م", "ن", "و", "ه", "ی"} 'Dim joined As String = String.Join("", charArray1) 'Me.charArray = joined Me.charArray = "ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی" Me.charCount = charArray.ToCharArray.Count End Sub Public Function NextLetter(Optional ByVal StartAt As Integer = 1) As String Dim count = (Me.CurrentNumber + StartAt) Dim divisor = count / Me.charCount Dim outstring As New StringBuilder If divisor <= 1 Then outstring.Append(charArray(Int32.Parse(count - 1))) Else Dim tempAlphaCount = Int(divisor) + 1 Dim groupRange = Int(divisor) * Me.charCount Dim alphaIndex = count - groupRange If alphaIndex = 0 Then tempAlphaCount = tempAlphaCount - 1 alphaIndex = Me.charCount End If alphaIndex -= 1 For i = 0 To tempAlphaCount - 1 outstring.Append(charArray(Int32.Parse(alphaIndex))) Next End If Me.CurrentNumber += 1 Return outstring.ToString End Function End Class
有没有人处理过这两种问题?有什么想法/建议吗?