I will change string To Int
I use from this code :
B4X:
If IsNumber(s) Then
I = s
End If
this code work truly for English numbers
but this code donot work truly for persian number and return for me false
Important : I need to find PERSIAN number .
anyone can help me ?
you can try this (may be some enhancement should be done with the function:
B4X:
Dim test As String = "۲۳"
Log (isFarsiLongNumber(test))
Sub isFarsiLongNumber (t As String) As Boolean
Dim farsiNumber As List
farsiNumber.Initialize2(Array As String ("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"))
For i = 0 To t.Length -1
Dim s As String
Dim index As Int
s = t.SubString2(i,i+1)
Log(i & " " & s)
index = farsiNumber.IndexOf(s)
If index < 0 Then
Return False
End If
Next
Return True
End Sub
hi again
haw can I this number convert to english number ==> "۲۳۸۰" => "2380"
I use from this code but I can't to complete this code :
B4X:
Sub FarsiNUM '(t As String) As Boolean
Dim farsiNumber As List
farsiNumber.Initialize2(Array As String ("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"))
For i = 0 To t.Length -1
Dim s As String
Dim index As Int
Dim mynum As String
Dim myNUM2 As String
Dim mmm As String
s = t.SubString2(i,i+1)
Log(i & " = " & s)
Select s
Case "۰"
mynum = "0"
Case "۱"
mynum = "1"
Case "۲"
mynum = "2"
Case "۳"
mynum = "3"
Case "۴"
mynum = "4"
Case "۵"
mynum = "5"
Case "۶"
mynum = "6"
Case "۷"
mynum = "7"
Case "۸"
mynum = "8"
Case "۹"
mynum = "9"
Case ""
mynum = ""
End Select
Log(mynum)
index = farsiNumber.IndexOf(s)
If index < 0 Then
Return False
End If
Next
Return True
End Sub
Sub F2EDigit(Input As String) As String
Return Input.Replace(Chr(1632), "0").Replace(Chr(1633), "1").Replace(Chr(1634), "2").Replace(Chr(1635), "3").Replace(Chr(1636), "4").Replace(Chr(1637), "5").Replace(Chr(1638), "6").Replace(Chr(1639), "7").Replace(Chr(1640), "8").Replace(Chr(1641), "9").Replace(Chr(1632), "0")
End Sub
Dim test As String = "۲۳۸۰"
Log (farsi2Number(test))
End Sub
Sub farsi2Number (t As String) As String
Dim farsiNumber As List
farsiNumber.Initialize2(Array As String ("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"))
Dim res As String
res = ""
For i = 0 To t.Length -1
Dim s As String
Dim index As Int
s = t.SubString2(i,i+1)
Log(i & " " & s)
index = farsiNumber.IndexOf(s)
If index < 0 Then
Return ""
Else
res = res & index
End If
Next
Return res
End Sub