I am trying to extract specific strings from my text. I have a string similar to this:
"blablabla(/)Hello Bob(|)bla(/)Hi(|)blablaba"
and I am trying to concatenate a string array of text between (/)
and (|)
but I cannot figure out a efficient way to do this. In this example I would want to return "Hello Bob" and "Hi". How can I effectively extract specific strings from a string in Swift?
Using a functional approach, you can:
(/)
, which returns an array of strings(|)
This is the code:
let array = string.componentsSeparatedByString("(/)")
.map { $0.componentsSeparatedByString("(|)") }
.filter { $0.count > 1 }
.map { $0[0] }
Given this input string:
let string = "blablabla(/)Hello Bob(|)bla(/)Hi(|)blablaba"
the result is:
["Hello Bob", "Hi"]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다