Midimaster Active Member Licensed User Jul 22, 2020 #1 The MAP.GET() returns my string as an object. Now I want to trim the string, but how to cast an object to string? B4X: 'this is easy: Dim word as String = MyPropery.Get("Name") word = word.Trim 'but how to cast in one line? 'this will not work: Dim oneLine as String = MyPropery.Get("Name").Trim Dim anotherLine as String = String(MyPropery.Get("Name")).Trim is there a way to do this in B4X?
The MAP.GET() returns my string as an object. Now I want to trim the string, but how to cast an object to string? B4X: 'this is easy: Dim word as String = MyPropery.Get("Name") word = word.Trim 'but how to cast in one line? 'this will not work: Dim oneLine as String = MyPropery.Get("Name").Trim Dim anotherLine as String = String(MyPropery.Get("Name")).Trim is there a way to do this in B4X?
Erel B4X founder Staff member Licensed User Longtime User Jul 22, 2020 #2 This cannot work: Dim oneLine as String = MyPropery.Get("Name").Trim There is no relation between the value returned from Map.Get and the left side type. You will need to use a variable or a sub like this: Code: Sub GetProperty(Key As String) As String Return MyProperty.Get(Key) End Sub Code: Dim OneLine As String = GetProperty("Name").Trim Upvote 0
This cannot work: Dim oneLine as String = MyPropery.Get("Name").Trim There is no relation between the value returned from Map.Get and the left side type. You will need to use a variable or a sub like this: Code: Sub GetProperty(Key As String) As String Return MyProperty.Get(Key) End Sub Code: Dim OneLine As String = GetProperty("Name").Trim
E emexes Expert Licensed User Longtime User Jul 22, 2020 #3 Or you could try a sub like this: B4X: Sub CastToString(S As String) As String Return S End Sub and then doing casts to String like this: B4X: Dim OneLine As String = CastToString( MyProperty.Get("Name") ).Trim Upvote 0
Or you could try a sub like this: B4X: Sub CastToString(S As String) As String Return S End Sub and then doing casts to String like this: B4X: Dim OneLine As String = CastToString( MyProperty.Get("Name") ).Trim
Midimaster Active Member Licensed User Jul 22, 2020 #4 ok, i have to write the casting functions. i see... thank you Upvote 0