Saturday, January 29, 2011

iPhone : Trimming space ,tabs ,newline from NSString

This will remove white space from both ends of a string:

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];

The whitespaceCharacterSet consists of spaces and tabs.

If you want to also remove newlines from the string, use the whitespaceAndNewlineCharacterSet:

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

Friday, January 28, 2011

how to set the title as left alignment in the UIButton in iPhone ?

Set the contentHorizontalAlignment:

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

You might also want to adjust the content left inset otherwise the
text will touch the left border:

btn.contentEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 0);

URL , URI & URN

A URI identifies a resource either by location or name. More often than not, most of us use URIs that defines a location to a resource. However, a URI does not have to specify the location of a specific representation.
For Example: URI for home image, http://www.cs.org/Icons/home. Note the absence of a file extension. The URI for the home image is still universally unique, but it does not specify the specific representation of the image (either a GIF, PNG, or JPG). The selection of the representation can be determined by the web server through HTTP content negotiation.

A URL is a URI but a URI is not a URL. Schemes in the URL (locator) and URN (name) categories form subsets of URI, and also (generally) disjoint sets.

A URL is a specialization of URI that defines the network location of a specific representation for a given resource. Taking the same example, there are actually 2 representations available for the home resource:

http://www.cs.org/Icons/home.gif
http://www.cs.org/Icons/home.png

These URIs also define the file extension that indicates what content type is available at the URL.

A Uniform Resource Name (URN) is a Uniform Resource Identifier (URI) that uses the urn scheme, and does not imply availability of the identified resource. Both URNs (names) and URLs (locators) are URIs, and a particular URI may be a name and a locator at the same time.
'URN' ::= "urn:" 'NID' ":" 'NSS'
where is the Namespace Identifier, and is the Namespace Specific String. Phrases enclosed in quotes are REQUIRED. The leading "urn:" sequence is case-insensitive. The Namespace ID determines the syntactic interpretation of the Namespace Specific String.
e.g. : urn:issn:0167-6423
The URN for the "Science of Computer Programming" journal, identified by its serial number.

A Uniform Resource Name (URN) functions like a person's name, while a Uniform Resource Locator (URL) resembles that person's street address. In other words: the URN defines an item's identity, while the URL provides a method for finding it.