0

Shortly I want to convert following string

"111---222-333"

to

"111", "222-333".

So I want to split with only "---" string, not with "-".

Java split can do it, but if i use str1.split(separator: "---") with "---",

then it says "Cannot convert value of type 'String' to expected argument type 'Character'"

Knowledge Drilling
  • 904
  • 1
  • 8
  • 20

1 Answers1

2

Other than split, there is also a method called components(separatedBy:) that accepts a StringProtocol as the parameter:

"111---222-333".components(separatedBy: "---")
Sweeper
  • 176,635
  • 17
  • 154
  • 256