2012-06-21 30 views

回答

2
NSString *str = @"http://www.abc.com/news/read/welcome-new-gig/03276"; 

str = [str stringByReplacingOccurrencesOfString:@"http://" 
           withString:@""]; 

希望這將幫助你......

+0

謝謝 - 你在哪裏,所以我會盡我所能接受你的答案。 (SO需要我再等6分鐘) –

1

substringFromIndex:。你也是明智的做一些邊界檢查。另外,我建議在提問之前查看文檔。

+0

這比依賴stringByReplacingOccuranceOfString的方法更好,它取代了字符串的所有實例而不僅僅是初始實例。使用本篤科恩的答案,像[str substringFromIndex:@「http://」.length],以確保您不會遇到這些副作用。 –

+0

好吧我會研究一下 - 謝謝:-) –

0
NSString *originalString = @"http://google.com"; 
NSString *substring = [originalString stringByReplacingOccurrencesOfString:@"http://" withString:@""]; 
0

可能要實際檢查您正在使用的「http://」在前面,並在每個實例而不是取代它。這個怎麼樣:

if([[str substringToIndex:@"http://".length] isEqualToString:@"http://"]) 
    str = [str substringFromIndex:@"http://".length]; 

這將是更強大,實際上將確保它開始以「http://」,而不是取代它的每一個實例。