Wednesday, December 25, 2013

Reverse print string

I have here is the reverse print NSString, make no mistake, not in C + +, that I will

------------------

NSString * s = @ "abcdefghijk";

char * p1, * p2;

p1 = p2 = s; / / p1, p2 point to the beginning of the string

while (p2) p2 + +;

p2 -; / / p2 point to the end of the string

/ / The following will start printing. . . . . .



-------------------

32 mac down, NSString is in C + + string is not like the same, there is a '\ 0', as it should not, because it is a class, then I'm in the end how
Reverse Print NSString it? ? ?

Experts answer:
Reply:
This class has a function of the length of the bar.

Get the length, then,,, - input, to get a single character from the last length of the
Reply:
 
NSString * str = @ "123456";
NSRange range;
range.length = 1;
for (int i = [str length] -1; i> = 0; i -)
{
range.location = i;
NSString * c = [str substringWithRange: range]; / / this is to take a string of letters
/ / The following will start printing. . . . . .
}

Reply:
Thank you,


reference to the second floor melody1304 reply:
C / C + + code

NSString * str = @ "123456";
NSRange range;
range.length = 1;
for (int i = [str length] -1; i> = 0; i -)
{
range.location = i;
NSString * c = [str substringWithRange: range]; / / this is to take a string of letters
......

Reply:
# Import

int main (int argc, const char * argv []) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * s = @ "123456789";
int lastIndex = [s length] -1;
for (int i = lastIndex; i> = 0; i -) {
NSLog (@ "% c", [s characterAtIndex: i]);
}
[Pool drain];
return 0;
}
Reply:
The NSString turn into char * not finished? Do not do it?

No comments:

Post a Comment