I am new to Iphone development. I have tried the following code, but it does not work with middle whitespace in UITEXTFIELD.
NSString *t1 = [txt.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
How can I avoid middle whitespace?
Use this code may this use full.
NSString *t1=[txt.text stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *t1= [txt.text stringByReplacingOccurrencesOfString:#" " withString:#""]
Related
When i try to parse xml containing email address say john#abc.com, it just shows "abc.com".
How can i make it to show the complete email address. In other cases i've removed some special charcters by using the following:-
string=[string stringByReplacingOccurrencesOfString:#"$" withString:#""];
but here i've to include the symbol "#" and characters before it.
Thanks for any help.
Well... finally found a solution for myself. I converted the xml data into a string and replaced characters. Below is the code:-
NSError* error;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
content=[content stringByReplacingOccurrencesOfString:#"#" withString:#"#"];
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
Problem Solved :)
NSString *string = #"$amdocs.com";
string=[string stringByReplacingOccurrencesOfString:#"$" withString:#"#"];
NSLog(#"%#",string);
maybe it will help you.
I have NSString #" (\n "Bi_ss" \n) "
I want to get String #"Bi_ss "
Any one has any idea about this ?
Thank you
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
From Cocoanetics...
Take a look at the NSString method stringByReplacingOccurrencesOfString:withString for example, this should be able to perform the basic task you want it to do.
i am getting one url from the server http: / /www.google.com, however due to space in between them it is not opening, please let me know how to remove the space in between them, so that it should open in safari.
To remove empty space:
str = [str stringByReplacingOccurrencesOfString:#" " withString:#""];
Use following to detect site or phone number in text view.
textview.dataDetectorTypes = UIDataDetectorTypeAll;
NSString *cleanString = [dirtyString stringByReplacingOccurrencesOfString:#"http: //" withString:#"http://"];
I'd wonder why you get this odd string in the first place, though.
NSString *str = #"hel lo";
[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
For remove empty spaces, please use below code,
str = [str stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
I have a NSString like this
NSString *mystring = #"RahulVyas";
Now I want to add this ' so the new string would be 'RahulVyas'
How to do this ?
How about:
NSString *newString = [NSString stringWithFormat:#"'%#'", mystring];
You just want to surround the string with single quotes, right? You can just use stringWithFormat:
mystring = [NSString stringWithFormat:#"'%#'", mystring];
NSString *mystring=#"'RahulVyas'";
NSLog(#"%#", mystring);
Seems to work just fine for me.
Is there any function to remove the white spaces from text message in objective c?
For eg:for "How are you",the result should be "howareyou"
Thanks in advance.
You could use NSString's componentsSeparatedByCharactersInSet with whitespaceCharacterSet to first split the string on the whitespace, and then join the components using NSArray's componentsJoinedByString.
eg.
NSString *myString=#"How are you";
myString = [[myString componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString: #""];
NSLog(myString); // displays Howareyou
Tom's approach isn't very efficient. What you want is:
-stringByTrimmingCharactersInSet:
NSString *myString = #"How are you";
myString = [myString stringByReplacingOccurrencesOfString:#" " withString:#""];