Android Question Split string from "-" to "-"

Mattiaf

Active Member
Licensed User
Hi, How can I split the following string
B4X:
-CA100-ISTITUTO PERTINI VIA CARPACCIO N° 18 A - N° 1 CHIAVE MECCANICA
in order to get only
B4X:
-CA100-
?

I'm trying with
B4X:
Dim strBeforeSplit As String
strBeforeSplit="-CA100-ISTITUTO PERTINI VIA CARPACCIO N° 18 A - N° 1 CHIAVE MECCANICA"
Dim strSplit() As String
strSplit=Regex.Split("-",strBeforeSplit)
Msgbox(strSplit(0)

but it doesn't work..
any idea? thanks
 
Solution
CA100 is the SECOND value! Regex starts at the first - to split. means:
1st item is an empty string,
2nd Item CA100,
3rd Item ISTITUTO PERTINI VIA CARPACCIO N° 18 A
and 4th item N° 1 CHIAVE MECCANICA

B4X:
    Dim strBeforeSplit As String
    strBeforeSplit="-CA100-ISTITUTO PERTINI VIA CARPACCIO N° 18 A - N° 1 CHIAVE MECCANICA"
    Dim strSplit() As String = Regex.Split("-",strBeforeSplit)
    Log($"AfterAplit: ${strSplit(1)}"$)

DonManfred

Expert
Licensed User
Longtime User
CA100 is the SECOND value! Regex starts at the first - to split. means:
1st item is an empty string,
2nd Item CA100,
3rd Item ISTITUTO PERTINI VIA CARPACCIO N° 18 A
and 4th item N° 1 CHIAVE MECCANICA

B4X:
    Dim strBeforeSplit As String
    strBeforeSplit="-CA100-ISTITUTO PERTINI VIA CARPACCIO N° 18 A - N° 1 CHIAVE MECCANICA"
    Dim strSplit() As String = Regex.Split("-",strBeforeSplit)
    Log($"AfterAplit: ${strSplit(1)}"$)
 
Upvote 1
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…