gpt4 book ai didi

ios - 使用正则表达式删除空行

转载 作者:行者123 更新时间:2023-11-28 18:30:28 24 4
gpt4 key购买 nike

我是 iOS 开发的新手,我有下面这样的数据,我想删除所有空行,请告诉我要应用的模式:

我已经将模式用作 @"(\r\n)"并将其替换为 @"",但它不起作用。请帮我解决这个问题

#EXTINF:-1 tvg-name="seedocs" tvg-logo="RT",RT





http://rt.ashttp14.visionip.tv/live/rt-global-live-HD/playlist.m3u8

#EXTINF:-1 tvg-name="hsn" tvg-logo="hsn",HSN TV

rtsp://hsn.mpl.miisolutions.net:1935/hsn-live01/_definst_/mp4:420p500kB31

#EXTINF:-1 tvg-name="us" tvg-logo="us",USTwit

http://bglive-a.bitgravity.com/twit/live/high

#EXTINF:-1 tvg-name="ALJAZEERA" tvg-logo="aljazeera",Aljazeera

rtmp://aljazeeraflashlivefs.fplive.net/aljazeeraflashlive-live/aljazeera_eng_high

#EXTINF:-1 tvg-name="bbc" tvg-logo="bbc",BBC World News



#EXTINF:-1 tvg-name="vevo" tvg-logo="vevo",Vevo

http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/06/prog_index.m3u8

#EXTINF:-1 tvg-name="vevo2" tvg-logo="vevo2",Vevo 2

http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch3/06/prog_index.m3u8

#EXTINF:-1 tvg-name="1HD" tvg-logo="1HD",1HD

rtmp://109.239.142.62/live/livestream3

最佳答案

[\r\n]+

您可以改用它。请参阅演示。替换为 \n

https://regex101.com/r/vV1wW6/26

NSString *string = @"Your multiline string";
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[\r\n]+" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"\n"];

关于ios - 使用正则表达式删除空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32691559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com