I need to validate a UITextField to replace a blank space ' ' with '%20' and was wondering how this is possible?
Check out the method stringByReplacingOccurrencesOfString:withString: on NSString if you are just looking to replace the characters in a string with another value.
Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.
NSString *originalString = @"Sample text with spaces";
NSString *newString = [originalString stringByReplacingOccurancesOfString:@" " withString:@"%20"];
If you are attempting to encode a URL, use stringByAddingPercentEscapesUsingEncoding: on NSString.
Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.
NSString *originalString = @"Sample text with spaces";
NSString *newString = [originalString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* string = @"Daylight by Maroon 5" ;
NSString* encodedString = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With