Adding backslash to String in Objective-c is not Working

Does anyone know of an easy way to add a single backslash () to an NSString in Objective-C?

I am trying to add a backslash between each byte of addresses. But after adding and printing the output is not coming as expected.

Output: "<IpAddress 0x00000002834809d0>" = { FourByteAddress = "0/\0/\0/\0"; };

Expected: "<IpAddress 0x00000002834809d0>" = { FourByteAddress = "0\0\0\0"; };

Can you post more details about your specific problem? I wrote some code to do this (see below) and it works just fine but I suspect that I’m missing some key element of the problem.

NSString * address = @"1.2.3.4";
NSArray * components = [address componentsSeparatedByString:@"."];
NSString * quotedAddress = [components componentsJoinedByString:@"\\."];
NSLog(@"%@", quotedAddress);
// prints: … 1\.2\.3\.4

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Adding backslash to String in Objective-c is not Working
 
 
Q