I have a two string like “SANFRANSICO” and “CHICAGO”
Now i want to make it like the string is in reverse but in a single string like “OOCGIASCNIAHRCFNAS”
I have done code but it gives me wrong result
check out my code
- (NSString *)changeString1:(NSString *)string string2:(NSString *)string2{
int first = [string length];
int second = [string2 length];
int total = first+second;
NSMutableString *str = [[NSMutableString alloc] init];
string = [self reverseString:string];
string2 = [self reverseString:string2];
for (int i=0; i<total+1; i++)
{
if (i%2==1) {
int j = i/2;
if(j < second){
NSString *ichar = [NSString stringWithFormat:@"%c", [string2 characterAtIndex:j]];
[str appendString:ichar];
}
else{
NSString *ichar = [NSString stringWithFormat:@"%c", [string characterAtIndex:j+1]];
NSLog(@"222 %d %@",j+1, ichar );
[str appendString:ichar];
check = YES;
}
}
else {
int j = i/2;
if(check == YES){
}
else{
NSString *ichar = [NSString stringWithFormat:@"%c", [string characterAtIndex:j]];
NSLog(@"1111 %d %@",j, ichar );
[str appendString:ichar];
}
}
}
return str;
}
I found the answer very soon after post this question sorry for posting this question
check out my answer