Objective c RangeOfString方法的奇怪返回

Objective c RangeOfString方法的奇怪返回,objective-c,nsrange,Objective C,Nsrange,代码的一点解释:我有一个dict,看起来像这样: HC_1 : test1, HC_2: test2, .... 如果我在ModifiedReportTemplateContent中找到HC_1,我会查找后面的第一个>并添加test1 -(NSMutableString*)almMapData:(NSDictionary *)aDictData; { NSMutableString *theModifiedReportTemplateContent = itsReportTemplateC

代码的一点解释:我有一个dict,看起来像这样:

HC_1 : test1, HC_2: test2, ....
如果我在ModifiedReportTemplateContent中找到HC_1,我会查找后面的第一个>并添加test1

 -(NSMutableString*)almMapData:(NSDictionary *)aDictData;
{

NSMutableString *theModifiedReportTemplateContent = itsReportTemplateContent mutableCopy];

for(id theCell in aDictData)
{
    NSRange theNameRange = [theModifiedReportTemplateContent rangeOfString:theCell];
    NSString *theNewContent = [theModifiedReportTemplateContent substringFromIndex:theNameRange.location];
    if(theNameRange.location != NSNotFound)
    {
        NSRange theCharRange = [theNewContent rangeOfString:@">"];
        long theIndex =((long)theCharRange.location+(long)theNameRange.location+1);
        [theModifiedReportTemplateContent insertString:[aDictData objectForKey:theCell] atIndex:theIndex];

    }
}

return theModifiedReportTemplateContent;

}
我的问题是,我打印的是图表,我有如下内容:

location=13, length=1
 {
  2001-01-01 00:00:00 +0000

  <object returned empty description>

}

因此,我对InsertString atIndex有一个例外。

它的ReportTemplateContent包含什么?Html内容如:NPV 100000 NPV IN 100000 200000 NPV=200000您最好使用XML解析器对其进行解析,然后修改DOM,然后将其写回。您当前的实现非常难看且容易出错。谢谢您的回答。我刚刚发现了NSXMLParser。你知道怎么用吗?