4
//viewdidload
{
str1 = [[NSMutableString alloc] initWithCapacity:0];
str2 = [[NSMutableString alloc] initWithCapacity:0];
}//

for (int pq=1; pq<=temp; pq++) 
{
str1 =  [NSMutableString stringWithString:[documentManager wholeTextForPage:pq] ] ;
[self.str2 appendString:str1];
NSLog(@"content of page chumma1:  %@",str1);
}
NSLog(@"cwhole text:  %@",str2

**这里 str1 在每次迭代时返回不同的字符串。我试图将 str1 返回的每个字符串附加到 str2。但是 str2 在第一次迭代时只返回 str1 返回的一个字符串。其他迭代返回的字符串不会附加到 str2。请帮我想办法解决这个问题。提前致谢。

感谢和问候VEERA **

4

5 回答 5

0

用这种方法试试......

NSMutableString *str1 = [[NSMutableString alloc]initWithCapacity:0];
NSMutableString *str2 = [[NSMutableString alloc]initWithCapacity:0];

for(int pq=1; pq<temp; pq++)
{
    str1 = [NSMutableString stringWithFormat:[documentManager wholeTextForPage:pq]];
    str2 = (NSMutableString *)[str2 stringByAppendingFormat:str1];
    NSLog(@"content of page chumma1:  %@",str1);
}

NSLog(@"cwhole text:  %@",str2);
于 2012-06-13T07:53:18.940 回答
0
Use stringByAppendingString see example:
But str2 should declare NSString

更新:

NSMutableString *str1 = [NSMutableString string];
NSString *str2 = @"";

for (int pq=1; pq<=temp; pq++) 
{
    str1 =  [NSMutableString stringWithString:[documentManager wholeTextForPage:pq] ] ;
    str2 = [str2 stringByAppendingString:str1];
}

这会将 str1 中的所有数据附加到 str2。

于 2012-06-13T06:01:26.063 回答
0

试试这样的..

....
for (int pq=0; pq < temp; pq++)  {
    str1 =  [NSMutableString stringWithString:[documentManager wholeTextForPage:pq] ] ;
    [self.str2 appendString:str1];
    NSLog(@"content of page chumma1:  %@",str1);
}

NSLog(@"cwhole text:  %@",str2
于 2012-06-13T06:01:35.140 回答
0

这样做附加字符串:

str1 = [[NSMutableString alloc] initWithCapacity:0];
for (int pq=1; pq<=temp; pq++) 
{
  str1 = [str1 stringByAppendingString:[NSString stringWithString:[documentManager wholeTextForPage:pq]]];
}
于 2012-06-13T06:05:04.270 回答
0
NSMutableString *str1= [NSMutableString new];
    for (int i =0; i < 10; i++) {
        [str1 appendString:@"Hi "];
    }   
    NSLog(@"%@",str1);

您的代码可能不起作用,因为 appendString:(NSString*)str 不是 NSMutableString。所以使用NSString。

给你代码试试这个

for (int pq=1; pq<=temp; pq++)
    [self.str2 appendString:[documentManager wholeTextForPage:pq]];
于 2012-06-13T06:05:36.567 回答