开发者

reverse of a string

i want a program to display the reverse of a string. my program should have two textViews and a button. the string entered by user in a textView should be taken when we press the button and the re开发者_如何学Pythonverse of that string should be displayed in the other textView. all the ib stuff to be done on window itself.

plz help me with code. forgive me if you feel the question is simple or basic.


I would suggest you read in the values from the textview into an array then reverse the array, something like this where array1 is a list of values from your textview

NSMutableArray *tmp = [[NSMutableArray alloc] init];

for(int x=[array1 count] - 1;x>=0; x--){
  [tmp addObject:[array1 objectAtIndex:x]];
}


What about this?

-(NSString *) revertString:(NSString*)stringToRevert
{
    NSMutableString *reversedStr;
    int len = [stringToRevert length];

    reversedStr = [NSMutableString stringWithCapacity:len];     

    while (len > 0)
      [reversedStr appendString:
           [NSString stringWithFormat:@"%C", [stringToRevert characterAtIndex:--len]]];   

    return reversedStr;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜