'B4J 7.51
Sub Test2
Dim Params As Map
Params.Initialize
'Params.Put("Key","ABC") 'without this row .Get Return something that can Not be Test As null
Dim MyString As String
MyString = Params.Get("Key")
Log(MyString)
'If IsNull(MyString) Then MyString = "123"
If MyString = Null Or MyString = "" Then MyString = "123"
Log(MyString)
End Sub
Sub IsNull(O As Object) As Boolean
Return (O=Null)
End Sub
'B4J 7.51
Sub Test2
Dim Params As Map
Params.Initialize
'Params.Put("Key","ABC") 'without this row .Get Return something that can Not be Test As null
Dim MyString As String
MyString = Params.Get("Key")
Log(MyString)
'If IsNull(MyString) Then MyString = "123"
If MyString = Null Or MyString = "" Then MyString = "123"
Log(MyString)
End Sub
Sub IsNull(O As Object) As Boolean
Return (O=Null)
End Sub
Sub Test2
Dim Params As Map
Dim o As Object
Params.Initialize
' Params.Put("Key","ABC") 'without this row .Get Return something that can Not be Test As null
Dim MyString As String
o = Params.Get("Key")
If o Is Object Then
MyString = o
Else
MyString = "123"
End If
Log(MyString)
End Sub
hi erel, ahhh
that Null is converted to "null" string is special.
because missing quotes maybe you can modify this window that is it more clear what kind of value is displayed.
MyString null String
MyString null Object
or
MyString = "null" to be equal to source code
I'm not sure this would be helpful...
All values for strings in this window are displayed without quotes. Also, how can we know if the value "null" wasn't set as a string?
This is the main reason I believe Erel suggests to avoid working with nulls - strings...
intuitiv i would expect empty string "" if there is no key found. and a method Params.KeyExists("Key")
other languages would raise an error but i not like error handling for every method.
B4X:
Dim MyString As String
MyString = Params.Get("Key")