B4J Question mix Select Case with string.Contains

MarcRB

Active Member
Licensed User
Longtime User
Hello,

Is there a quick way to mix the Select Case statement with string.Contains()?
For example: I will have a select case , but the values at each case will be parts of the original value.
It can be at all positions in the string.

Serialnumber with a A in it do sub A
Serialnumber with a B in it do Sub B

Sure I can do this by multiple If strSerial.Contains("A") Then ..... End If but I think it can be done smarter.

Wish:
Select Case txtSerialNumber.text  
    Case.Contains("7362")
        SetMark("Samsung")
    Case.Contains("AT2")
        SetMark("Pioneer")
    Case Else
        SetMark("Unknown")
End Select

'this is not working as you can expect


Best Regards
 
Last edited:
Solution
You need to use Select True.
B4X:
Dim SerialNumber As String = txtSerialNumber.Text
Select True
    Case SerialNumber.Contains("7362")
        SetMark("Samsung")
    Case SerialNumber.Contains("AT2")
        SetMark("Pioneer")
    Case Else
        SetMark("Unknown")
End Select
Top