gpt4 book ai didi

ios - 如何在iOS中将内容添加到html文件

转载 作者:行者123 更新时间:2023-12-01 17:31:12 24 4
gpt4 key购买 nike

我想向项目资源中可用的html文件添加内容。
例如:-下面是html,里面有一些标签

<body >
<div id="abc">
<div>{feed}<br /></div>
<div >{date}</div>
</div>
</body>

我想用其中的一些字符串替换{feed},{date}并在 UIwebview中显示该html
请给我一些指导以实现它
提前致谢

最佳答案

//Get your HTML file path.
NSString * htmlFilePath = [[NSBundle mainBundle] pathForResource:@"YOUR_FILE_NAME" ofType:@"html"];

//get the file content to a NSString.
NSString *htmlContentString = [NSString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];

// Then you need to replace a string (say 'stringA') with new string (say 'stringB')
htmlContentString = [htmlContentString stringByReplacingOccurrencesOfString:stringA withString:stringB];

//Then load the new HTML string to your webView

[yourWebView loadHTMLString:htmlContentString baseURL:nil];

关于ios - 如何在iOS中将内容添加到html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21930484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com