I want to fetch a part of string from a string. E.g. I have a string say sampleStringUrl
which holds "http://some.something.net/update/user". So, I want to get only "some.something.net" from sampleStringUrl
.
Asked
Active
Viewed 39 times
-4

Anuranjan Bose
- 201
- 1
- 3
- 16
-
2"I want to" is not a good question, specially when the question shows no attempt from OP to solve the issue – Joakim Danielson Nov 19 '19 at 08:02
-
@JoakimDanielson Okay, I'll keep that in mind from next time. – Anuranjan Bose Nov 19 '19 at 10:47
1 Answers
1
Like that you want to get Host URL.
var urlString = "https://stackoverflow.com/questions/6162522/get-the-domain-part-of-an-url-string"
var url = URL(string: urlString)
var domain = url?.host
print(domain!) //stackoverflow.com

Rushabh Shah
- 396
- 3
- 19