Created
July 21, 2012 14:24
-
-
Save lqik2004/3155942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| originTextArray=[NSMutableArray arrayWithCapacity:0]; | |
| transTextArray=[NSMutableArray arrayWithCapacity:0]; | |
| NSString *rex=@"<[^>]*?>([^<]*)"; | |
| NSArray *r=[self.item.summary arrayOfCaptureComponentsMatchedByRegex:rex]; | |
| BOOL judge=YES; | |
| for(NSArray *tmp in r){ | |
| NSString *content=[tmp objectAtIndex:1]; | |
| //过滤连续标签中间的空内容 | |
| if(content.length>0){ | |
| //judge为YES,判断为原文 | |
| if(judge){ | |
| [originTextArray addObject:content]; | |
| judge=NO; | |
| }else { | |
| [transTextArray addObject:content]; | |
| judge=YES; | |
| } | |
| } | |
| } | |
| // | |
| NSMutableString *tmp=[NSMutableString string]; | |
| //下面的if语句防止当原文和翻译段落不相等程序出现崩溃 | |
| if(originTextArray.count>=transTextArray.count){ | |
| for(int i=0;i<originTextArray.count;i++){ | |
| [tmp appendString:[originTextArray objectAtIndex:i]]; | |
| //换行符 | |
| [tmp appendString:@"\n\n"]; | |
| if(transTextArray.count>=i){ | |
| [tmp appendString:[transTextArray objectAtIndex:i]]; | |
| [tmp appendString:@"\n\n"]; | |
| } | |
| } | |
| } | |
| _textView.text=tmp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment