Android Question How to replace specific text or numbers in an array

Shahid Saeed

Active Member
Licensed User
Longtime User
I am very beginner to android and Basic4Android development, I am trying to get rid of a problem I am facing regarding how to replace some specific numbers and text in an array:

I am trying to do something like:

Dim a_arabic(12), arabic_num(10), num_text, num_num, number, number4 As String

a_arabic = Array As String("يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")
arabic_num = Array As String ("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٧", "٩")

number = 3
num_text = number.Replace(number, a_arabic)
Here what I want; it should get given number from 1-12 and replace it with the value of a_arabic array in that number.

-----------------
number4 = 3214
num_num = number4.Replace(number4, arabic_num)
Here what i want; it should replace all numbers with there respected numbers from the arabic_num array

Please give me the correct way to achieve what I am looking for.

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
in arabic you have 12 single numbers?
I just know 0,1,2,3,4,5,6,7,8,9
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
  Dim a_arabic(12), arabic_num(10) As String

   a_arabic = Array As String("يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")
   arabic_num = Array As String ("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٧", "٩")
 
   Dim str,dummy, num_text As String
   str = "1234"
   num_text = ""
   For i = 0 To str.Length-1
     dummy = str.SubString2(i,i+1)
     num_text = num_text &  arabic_num(dummy)
   Next
   Log(num_text)
I dont can read or write arabic. So this is rigth i hope...
 
Last edited:
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
@DonManfred

The numbers are same as 10 but the array of 12 numners are months, which i guess are 12 as well in english.

@Erel

Thanks for the quick reply, I will try your code and give you update.
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
@Erel & @DonManfred

Thank you so much I have mixed your code and got what I wanted, I am posting the code for reference if anyone else willing to do for other languages they can use it.

Sub Globals
Dim arabic_name() As String = Array As String("يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")
Dim arabic_num(10) As String
arabic_num = Array As String ("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٧", "٩")
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("sc03")

Dim dd, yyyy, dummy1, dummy2, Day, Month, Year As String
Month = ConvertNumberToName(DateTime.GetMonth(DateTime.Now))

yyyy = DateTime.GetYear(DateTime.Now)
Year = ""
For i = 0 To yyyy.Length-1
dummy1 = yyyy.SubString2(i,i+1)
Year = Year & arabic_num(dummy1)
Next
dd = DateTime.GetDayOfMonth(DateTime.Now)
Day = ""
For i = 0 To dd.Length-1
dummy2 = dd.SubString2(i,i+1)
Day = Day & arabic_num(dummy2)
Next


DateAR.Text = ( Day & " " & Month & " " & Year )

End Sub

Sub ConvertNumberToName(Number As Int) As String
Return arabic_name(Number -1)
End Sub
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
Code:
B4X:
Sub Globals
Dim arabic_name() As String = Array As String("يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")
Dim arabic_num(10) As String
arabic_num = Array As String ("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٧", "٩")
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("sc03")

Dim dd, yyyy, dummy1, dummy2, Day, Month, Year As String
Month = ConvertNumberToName(DateTime.GetMonth(DateTime.Now))

yyyy = DateTime.GetYear(DateTime.Now)
Year = ""
For i = 0 To yyyy.Length-1
dummy1 = yyyy.SubString2(i,i+1)
Year = Year & arabic_num(dummy1)
Next 
dd = DateTime.GetDayOfMonth(DateTime.Now)
Day = ""
For i = 0 To dd.Length-1
dummy2 = dd.SubString2(i,i+1)
Day = Day & arabic_num(dummy2) 
Next


DateAR.Text = ( Day & " " & Month & " " & Year )

End Sub

Sub ConvertNumberToName(Number As Int) As String
Return arabic_name(Number -1)
End Sub
 
Upvote 0
Top