SubNames: IsArray, ArrayType.
Descriptions:
IsArray checks if an object variable is an array.
Return value: Boolean - True if the variable is an array.
ArrayType checks the type of data contained in an array.
Return value: String - Type of data ("String", "Int", "Float"...)
[Correction: it returned "String" also for arrays of objects]
IsArray
ArrayType
Link to the original post.
Example and test:
LOG:
arrByte is array = true
arrShort is array = true
arrInt is Array = true
arrLong is array = true
arrFloat is array = true
arrChar is array = true
arrString is array = true
_______________________
Type of arrByte is Byte
Type of arrShort is Short
Type of arrInt is Int
Type of arrLong is Long
Type of arrFloat is Float
Type of arrChar is Char
Type of arrString is String
Tags: Array, Types, GetType
Descriptions:
IsArray checks if an object variable is an array.
Return value: Boolean - True if the variable is an array.
ArrayType checks the type of data contained in an array.
Return value: String - Type of data ("String", "Int", "Float"...)
[Correction: it returned "String" also for arrays of objects]
IsArray
B4X:
Public Sub IsArray(Var As Object) As Boolean
Dim VarType As String = GetType(var)
Return VarType.StartsWith("[")
End Sub
ArrayType
B4X:
Public Sub ArrayType(Var As Object) As String
Dim Res As String
Dim VarType As String = GetType(Var)
If VarType.StartsWith("[") Then
Dim SecondChar As String = VarType.SubString2(1,2)
Select Case SecondChar
Case "B"
Res = "Byte"
Case "S"
Res = "Short"
Case "I"
Res = "Int"
Case "J"
Res = "Long"
Case "F"
Res = "Float"
Case "D"
Res = "Double"
Case "C"
Res = "Char"
Case "L"
If VarType.Contains("String") Then
Res = "String"
Else
Res = "Object"
End If
Case Else
Res = ""
End Select
End If
Return Res
End Sub
Link to the original post.
Example and test:
B4X:
Private Sub Test
Private arrByte() As Byte
Private arrShort() As Short
Private arrInt() As Int
Private arrLong() As Long
Private arrFloat() As Float
Private arrChar() As Char
Private arrString() As String
Log("arrByte is array = " & IsArray(arrByte))
Log("arrShort is array = " & IsArray(arrShort))
Log("arrInt is Array = " & IsArray(arrInt))
Log("arrLong is array = " & IsArray(arrLong))
Log("arrFloat is array = " & IsArray(arrFloat))
Log("arrChar is array = " & IsArray(arrChar))
Log("arrString is array = " & IsArray(arrString))
Log("_________________________________")
Log("Type of arrByte is " & ArrayType(arrByte))
Log("Type of arrShort is " & ArrayType(arrShort))
Log("Type of arrInt is " & ArrayType(arrInt))
Log("Type of arrLong is " & ArrayType(arrLong))
Log("Type of arrFloat is " & ArrayType(arrFloat))
Log("Type of arrChar is " & ArrayType(arrChar))
Log("Type of arrString is " & ArrayType(arrString))
End Sub
LOG:
arrByte is array = true
arrShort is array = true
arrInt is Array = true
arrLong is array = true
arrFloat is array = true
arrChar is array = true
arrString is array = true
_______________________
Type of arrByte is Byte
Type of arrShort is Short
Type of arrInt is Int
Type of arrLong is Long
Type of arrFloat is Float
Type of arrChar is Char
Type of arrString is String
Tags: Array, Types, GetType
Last edited: