你可以使用NSString的stringByReplacingOccurrencesOfString:withString:方法来替换字符串中的内容。下面是一个示例代码:

NSString *str = @"www.baidu.com";
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index.b1c2c99e" withExtension:@"js" subdirectory:@"h5/static/js"];

// 将url转换成字符串
NSString *urlString = [url absoluteString];

// 替换字符串中的内容
urlString = [urlString stringByReplacingOccurrencesOfString:@"localhost.com" withString:str];

// 将替换后的字符串转换成NSURL
NSURL *newUrl = [NSURL URLWithString:urlString];

// 使用新的URL
// ... 进行接下来的操作

上述代码将url转换成字符串urlString,并使用stringByReplacingOccurrencesOfString:withString:方法将其中的localhost.com替换成str。然后,将替换后的字符串urlString转换成新的NSURL对象newUrl,你可以使用newUrl进行接下来的操作

ios 获取到了NSString str = wwwbaiducom NSURL url = NSBundle mainBundle URLForResourceindexb1c2c99e withExtensionjs subdirectoryh5staticjs; 这里面的内容替换里面所有的localhostcom 替换成str

原文地址: https://www.cveoy.top/t/topic/itVI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录