- ( BOOL ) textField: ( UITextField * )textField shouldChangeCharactersInRange: ( NSRange )range replacementString: ( NSString * )string {
NSString *strCurrent;
if ( range.length > 0 ) { // deleting
int iNumberOfDeletedCharacter = [ string length ];
int iNumberOfRestCharacter = [ [ textField text ] length ] - iNumberOfDeletedCharacter;
strCurrent = [ [ textField text ] substringToIndex: iNumberOfRestCharacter - 1 ];
}
else { // adding
strCurrent = [ [ textField text ] stringByAppendingString: string ];
}
MyNSLog( @"%@", strCurrent );
}
This code has a problem in deleting part when characters of 2byte languages are entering.
Do you know easy ways for this?
Thank you for reading.
It’s not clear from your question what you are trying to achieve. If you want to calculate the resulting string after the edit: