Reputation: 53687
In my app i want to create html file from arrays, can anyone know how this can be achieved?
Thanks in advance!
Upvotes: 2
Views: 4168
Reputation: 2014
this is acutally quite easy:
You can start with an NSMutableString and build up a large String which you can convert later in a file:
NSArray *yourArray = [NSArray arrayWithObjects: @"green", @"blue", @"red", nil];
NSMutableString *htmlText = [[NSMutableString alloc] init];
[htmlText appendFormat: @"<html><head><title>TEST</title></head>"];
[htmlText appendFormat: @"<body>"];
[htmlText appendFormat: @"<ul>"];
for ( NSString *tmpText in yourArray] )
{
[htmlText appendFormat: @"<li>%@</li>", tmpText];
}
[htmlText appendFormat: @"</ul>"];
[htmlText appendFormat: @"</body>"];
[htmlText appendFormat: @"</html>"];
// create the file
NSError *error = nil;
[htmlText writeToFile:yourPath atomically:YES encoding: NSUTF8StringEncoding error:&error];
if ( error )
{
// do some stuff
}
Upvotes: 10