2010-10-25 18 views
6
NSString *test = @"d'escape"; 
NSLog(@"%@", [test stringByReplacingOccurrencesOfString:@"'" withString:@"\'"]); 

मुझे इस गलतअंक stringByReplacingOccurrencesOfString साथ आईओएस में एकल उद्धरण से बचने: widthString

2010-10-25 15:10:54.833 MyApp[7136:207] d'escape 

मैं क्या कर रहा हूँ प्रिंट? मैं इस प्राप्त करना चाहते हैं:

2010-10-25 15:10:54.833 MyApp[7136:207] d\'escape 

उत्तर

18

\ ही सी में विशेष वर्ण आप स्रोत में यह से बचने के लिए की जरूरत है।

[test stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"] 
//               ^^ 
+0

मैंने सोचा कि यह कुछ बेवकूफ था जिसे मैं याद कर रहा था ^^ बहुत बहुत धन्यवाद –

संबंधित मुद्दे