Android Question How to convert key of a Map from String to integer

saeed10051

Active Member
Licensed User
Longtime User
Dear All i have a key value map, the key is a roll number for students but initially when i am picking it from a csv file it is being treated as a string, however i want to convert this string to integer, so that i can use it somewhere else in my code and increment it in order to jump to another record can anyone tell me how to convert string into integer and vice versa
 

DonManfred

Expert
Licensed User
Longtime User
You can not change the key of a Map. Create a new map with int-keys if you want.

You can convert a string to int like this
B4X:
dim test as string = "12345" ' your string (whereever it comes from)
dim intvalue as Int = test
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime User
You can not change the key of a Map. Create a new map with int-keys if you want.

You can convert a string to int like this
B4X:
dim test as string = "12345" ' your string (whereever it comes from)
dim intvalue as Int = test
Thanks DonManfred, actually i am using following code,
Dim su As StringUtils
Dim Table As List
Table = su.LoadCSV(File.DirAssets, "classdata.csv", ",")
m.Initialize
For Each row() As String In Table
Dim st As StudenType = CreateStudenType(row(0), row(1), row(2), row(3), row(4))
m.Put(st.roll, st)
here i am writing For Each row() as String In Table
therefore each type of data in the row() list should be a string, however i want to make the data for row(0) as integer, as then i can easily use it
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Following @DonManfred advice, did you try the following?
B4X:
Dim st As StudenType = CreateStudenType(row(0), row(1), row(2), row(3), row(4))
dim sroll as int = st.roll 'or even dim sroll as int = row(0)
m.Put(sroll, st)
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime User
Thanks udg and DonManfred. i have defined another variable as integer and it worked. Thanks.
Another thing that i want to ask is that can i put my csv file and the student pics in some external server, so that if new students are enrolled then all i need to do is to update the csv file and put a pic of the new student in the pics folder instead of recompiling the app everytime a new student is added or removed.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Why not? Having a remote DB where to store students' data will make things easier for you. Look for RDC2 for a start point on how to set up the preferred way to interact with a remote DB through a middle-layer component tha facilitates a lot this kind of projects.
If you have not available a VPS (even a low-cost one) than search for threads about using PHP along with B4A and remote DB on a shared server.
 
Last edited:
Upvote 0
Top