Splendid
Splendid

Reputation: 1061

avoid middle whitespace in UITextField

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?

Upvotes: 2

Views: 449

Answers (2)

Suresh D
Suresh D

Reputation: 4305


Use this code may this use full.

NSString *t1=[txt.text stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

Upvotes: 6

GendoIkari
GendoIkari

Reputation: 11914

NSString *t1= [txt.text stringByReplacingOccurrencesOfString:@" " withString:@""]

Upvotes: 1

Related Questions