Lakshmi
Lakshmi

Reputation: 585

How trim the spaces given in a word for textField

I have a word i.e., P roduct Name in a textfield . we have to trim the space between "P" and "r".

Can you please suggest the solution for this.

Thanks in advance.

Upvotes: 0

Views: 301

Answers (2)

user7369234
user7369234

Reputation:

This can help you to remove spaces between two words.

NSString *string = @"P roduct Name"; NSString *secondString = [string stringByReplacingOccurrencesOfString:@" " withString:@""];

Output: ProductName

If You want to remove white spaces at start and end of your string

NSString *s = @" Product Name "; s = [s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

Output: 'Product Name'

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163318

There is no real reliable solution for this - there is not enough information provided.

(Unless of course you iterated through a word list, which would be, well, horribly inefficient)

P and r could be separate words for all the computer cares..

Upvotes: 2

Related Questions