我们说我有www.GOOgle.com /.......
我想将其更改为www.google.com / ....
并保留url的其余部分。
我尝试了// I am taking input from textfield and making the nsurl.
NSURLComponents *components = [NSURLComponents componentsWithString: _textfield.text]; // input from textfield
[[components host] lowercaseString];
NSURL *urlin = [components URL]; //but this gives, www.GOOgle.com
,但它没有用。
Nancy.1.4.4
Nancy.Authentication.Forms.1.4.1
Nancy.Hosting.Self.1.4.1
Nancy.Viewengines.Razor.1.4.3
Microsoft.AspNet.Razor.2.0.30506.0
任何领导都表示赞赏。
答案 0 :(得分:2)
作为@Larme建议您可以在url中使用setHost方法
见下面的例子
NSURLComponents *components = [NSURLComponents componentsWithString: @"https://sTackoverFlow.com/questions/47924276/how-to-convert-host-of-nsurl-to-lowercase"];
[components setHost:[components.host lowercaseString] ];
NSLog(@"%@",components.URL)
ħ TTPS://stackoverflow.com/questions/47924276/how-to-convert-host-of-nsurl-to-lowercase
注意:
添加String需要http:// ,否则您将获得主机nil 例如https://www.sTackoverFlow.com/questions/47924276/how-to-convert-host-of-nsurl-to-lowercase它会起作用
,而
www.sTackoverFlow.com/questions/47924276/how-to-convert-host-of-nsurl-to-lowercase
答案 1 :(得分:0)
如果你的字符串只是url,你可以试试这个,
let strURL = "http://GOogLe.Com/Testt/xyz"
let url = NSURL(string: strURL)
let domain: String = (url?.host)! //get your host name
print(domain) //GOogLe.Com
let str = strURL.replacingOccurrences(of: domain, with: domain.lowercased())
print(str) //http://google.com/Testt/xyz
答案 2 :(得分:-1)
<强>示例强>: NSString * lowerCaseStringValue = [_textfield.text lowercaseString]; [NSURLComponents componentsWithString:lowerCaseStringValue];