我正在尝试按顺序在“调试”窗口中显示波斯语字母。一旦它到达最后一个字母,后续字母将乘以它们所在的组。所以,例如,如果我想显示alef(ا) - 字母“A”的波斯语,我将从索引1开始如果我的指数达到33(波斯语有32个字母),则应显示(اا)。
下面的代码适用于拉丁字母(例如“abcdefj ...”),但是对于波斯语/阿拉伯语,我有两个问题。
对于需要加倍的角色,例如“شش”(没有 它显示为“شش”。
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
之前有没有人处理过这两类问题?有什么想法/建议吗?
答案 0 :(得分:0)
计算出字符串中有一个2805的Unicode(不是预期的2804)。删除它会给出正确的计数。将它放在两个字母之间也允许不加入字母。