Other Parameter problem

cxbs

Active Member
Licensed User
Longtime User
Hello everyone!
I don't know why passing the same parameters results in different results.

B4X:
Sub Join2(a As Object,b As String)
    Dim sb As StringBuilder
    sb.Initialize
    For i=1 To 9
        sb.Append(a).Append(i)
    Next
    Log("a:" & sb.ToString) 'a:818283848586878889
    sb.Initialize
    For i=1 To 9
        sb.Append(b).Append(i)
    Next
    Log("b:" & sb.ToString) 'b:123456789
End Sub

Private Sub Button1_Click
    Join2(Chr(8),Chr(8))
End Sub
 

agraham

Expert
Licensed User
Longtime User
Probably because the parameters are of two different types. The String parameter Chr(8) is regarded as a character that can be directly appended to a StringBuilder while the Object parameter is having a default ToString() conversion applied before being appended resulting in the String value "8".
 
Upvote 1
Top