我想为具有不同标签名称的每一行输出标签,并希望将每个标签保存在一个文件中。我可以写文件,但是写完了。如何将每一行写入不同的文件?
输入:
英国泰坦尼克号
leondradicapro 凯特
德国酒店 hüßßan
tomhanks 安吉娜
输出:
<language>english<language/>
<movie>titanic<movie/>
<Actor>leondradiacpro<Actor/>
<Actress>kate<Actress/>
<language>German<language/>
...
代码:
for (NSString *str in lineFile)
{
if([str hasPrefix:@"english "])
{
NSMutableArray *dd = [[NSMutableArray alloc] initWithArray:[[str stringByReplacingOccurrencesOfString:@"english" withString:@""] componentsSeparatedByString:@" "]];
NSArray *tag = [NSArray aarrayWithObjects:@"er",@"langauge",@"movie",@"actor",@"kate",nil];
NSMutableString *output =[[NSMutableString alloc] init];
NSUInteger tagindex =0;
for (NSString *words in word)
{
if(tagindex >=[tag count])
{
NSLog(@"dad");
break;
}
[output appendFormat:@"<%@>%@<%@>\n", [tag objectAtIndex:tagindex],words,[tag objectAtIndex:tagindex]];
NSLog(@"%@",output);
[output writeToFile:@"/Users/xx/Desktop/homework.txt" atomically:YES encoding:NSASCIIStringEncoding error:NULL];
tagindex++;
现在我只能阅读语言和电影(第一行)我如何添加第二行和标签