// 'strBodyAll' is a variable that has text you are dealing with ('strBodyAll'에서 여러줄을 한줄로 바꿀려고 한다.)
// '\r' 은 뉴라인이고, '+'은 그앞의 표현('\r')이 한줄또는 그이상이 나타나는것을 말한다.
NSRegularExpression *regEx= [NSRegularExpression regularExpressionWithPattern:@"\r+" options:NSRegularExpressionCaseInsensitive error:nil];
// Replacing actually happens here with one new line('\r') (실제로 여기서 치환이 일어난다.)
[regEx replaceMatchesInString:strBodyAll options:NSRegularExpressionCaseInsensitive range:NSMakeRange(0, [strBodyAll length]) withTemplate:@"\r"];
// =================Bonus==================
// If you want to how many replace will be happen, just use below code (만약 몇개가 치환되는지 알고 싶으면 아래 코드를 사용할것)
// 'numberOfMatches' variables has the number of matched multilple new
lines in 'strBodyAll' ('numberOfMatches'변수는 'strBodyAll'에서 나타는 여러줄의 총 수를
말한다.
NSUInteger numberOfMatches = [regEx numberOfMatchesInString:strBodyAll
options:0
range:NSMakeRange(0, [strBodyAll length])];
'IT > iOS' 카테고리의 다른 글
iOS7에서 asset catalog를 이용한 Lite버전의 App Icon 설정하기 (0) | 2013.09.29 |
---|---|
iOS7 대응 하기 (0) | 2013.09.24 |
UISlider에 이미지 붙히기 (0) | 2013.05.12 |
아이폰 UI 싸이즈 (0) | 2013.05.12 |
이미지 컨트롤에 맞게 자동으로 늘여서 사용하기 (0) | 2013.05.11 |