I have source code to get url file name
eg:
http://www.google.com/a.pdf
I hope to get a.pdf
because the way to join the two NSStrings that I can get is "appendString", which is just for adding a line on the right side, so I planned to tag each char on the right side of the line <http://www.google.com/ a.pdf 'when it reaches the char' / 'value, stop checking, return the line fdp.a, after which I will change fdp.a to a.pdf
source codes below
-(NSMutableString *) getSubStringAfterH : originalString:(NSString *)s0 { NSInteger i,l; l=[s0 length]; NSMutableString *h=[[NSMutableString alloc] init]; NSMutableString *ttt=[[NSMutableString alloc] init ]; for(i=l-1;i>=0;i--) //check each char one by one from the right side of string 'http://www.google.com/a.pdf', when it reach at the char '/', stop { ttt=[s0 substringWithRange:NSMakeRange(i, 1)]; if([ttt isEqualToString:@"/"]) { break; } else { [h appendString:ttt]; } } [ttt release]; NSMutableString *h1=[[[NSMutableString alloc] initWithFormat:@""] autorelease]; for (i=[h length]-1;i>=0;i--) { NSMutableString *t1=[[NSMutableString alloc] init ]; t1=[h substringWithRange:NSMakeRange(i, 1)]; [h1 appendString:t1]; [t1 release]; } [h release]; return h1; }
h1 can reuse the coorect a.pdf line, but if it returns to the codes where it was called, after a while the system reports "double free *** set a breakpoint in malloc_error_break for debugging
I checked for a long time and realized that if I delete the code
ttt = [s0 substringWithRange: NSMakeRange (i, 1)];
everything will be OK (of course, getSubStringAfterH cannot return the result of the root process that I expected.), error messages are not reported.
I have been trying to fix the error for several hours, but still do not know.
Welcome any comment
Thanks interdev
iphone
arachide Mar 14 2018-10-10T00: 00Z
source share