NSString *fmtpAudio = @"a=fmtp:111 ";
NSString *stereoString = @";stereo=1;sprop-stereo=1";
NSArray *componentArray = [localSdpMutableStr componentsSeparatedByString:fmtpAudio];
if (componentArray.count >= 2) {
NSString *component = [componentArray objectAtIndex: 1];
NSArray *fmtpArray = [component componentsSeparatedByString:@"\r\n"];
if (fmtpArray.count > 1) {
NSString *fmtp = [fmtpArray firstObject];
NSString *fmtpAudioOld = [NSString stringWithFormat:@"%@%@", fmtpAudio, fmtp];
fmtpAudio = [NSString stringWithFormat:@"%@%@%@", fmtpAudio, fmtp, stereoString];
NSString *stereoEnabledSDP = [NSString stringWithString: localSdpMutableStr];
stereoEnabledSDP = [stereoEnabledSDP stringByReplacingOccurrencesOfString: fmtpAudioOld withString: fmtpAudio];
localSdpMutableStr.string = stereoEnabledSDP;
}
}
Consider below example String:
a=fmtp:93 av=2\r\n
a=fmtp:111 av=1\r\n
a=fmtp:92 av=2\r\n
In the above example string,
a=fmtp:111can appear anywhere in the string.We have to get the string between
a=fmtp:111and the next first appearance of\r\nwhich isav=1in our caseNow we have to append
;stereo=1;sprop-stereo=1toav=1and append back to the original string.The final output should be
a=fmtp:93 av=2\r\n a=fmtp:111 av=1;stereo=1;sprop-stereo=1\r\n a=fmtp:92 av=2\r\n
Is it possible to achieve the above chunk of logic with Replace with Regex pattern?