Android Code Snippet Check language direction based on dailing code

B4X:
'Assume all languages are LTR direction except these:
Public Sub isRTL(number As String) As Boolean
    Dim b As Boolean=False
    
    If number.StartsWith("967") Then b=True
    If number.StartsWith("973") Then b=True
    If number.StartsWith("98") Then b=True
    If number.StartsWith("964") Then b=True
    If number.StartsWith("972") Then b=True
    If number.StartsWith("962") Then b=True
    If number.StartsWith("965") Then b=True
    If number.StartsWith("961") Then b=True
    If number.StartsWith("968") Then b=True
    If number.StartsWith("92") Then b=True
    If number.StartsWith("970") Then b=True
    If number.StartsWith("974") Then b=True
    If number.StartsWith("966") Then b=True
    If number.StartsWith("963") Then b=True
    If number.StartsWith("971") Then b=True
    If number.StartsWith("20") Then b=True
    If number.StartsWith("216") Then b=True
    If number.StartsWith("212") Then b=True
    If number.StartsWith("213") Then b=True
    If number.StartsWith("218") Then b=True
    If number.StartsWith("222") Then b=True
    If number.StartsWith("249") Then b=True
    If number.StartsWith("211") Then b=True
    If number.StartsWith("252") Then b=True
    
    Return b   
End Sub
 

Sandman

Expert
Licensed User
Longtime User
There's more than one way to skin that cat.
B4X:
Public Sub isRTL(number As String) As Boolean
	Return " 967 973 98 964 972 962 965 961 968 92 970 974 966 963 971 20 216 212 213 218 222 249 211 252 ".Contains(" " & number & " ")
End Sub
 

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
There's more than one way to skin that cat.
B4X:
Public Sub isRTL(number As String) As Boolean
    Return " 967 973 98 964 972 962 965 961 968 92 970 974 966 963 971 20 216 212 213 218 222 249 211 252 ".Contains(" " & number & " ")
End Sub
number is like 967xxxxxxxxx , your code will return false!
 

Sandman

Expert
Licensed User
Longtime User
number is like 967xxxxxxxxx , your code will return false!
Sorry, I misread your code and thought you called the sub with the areacode, not the full phonenumber. This should work like your code:
B4X:
Public Sub isRTL(number As String) As Boolean
	Dim areacodes() As String = Regex.Split(",", "967,973,98,964,972,962,965,961,968,92,970,974,966,963,971,20,216,212,213,218,222,249,211,252")
	For Each areacode As String In areacodes
		If number.StartsWith(areacode) Then Return True
	Next
	Return False
End Sub
 
Top