I want to similar a Tamil keyboard
Function: when I press the A button, I want show அ and when I press AA I want to show ஆ.
This is what I’ve tried so far.
NSMutableString *updatedText = [[NSMutableString alloc] initWithString:textView.text];
[updatedText insertString:text atIndex:range.location];
NSLog(@"%i",range.location);
NSRange replaceRange = range , endRange = range;
if (text.length > 0)
{
NSLog(@" text length %i",text.length);
replaceRange.length= text.length;
}
else
{
replaceRange.length = 2; // length of "hi" is two characters
replaceRange.location -= 1; // look back one characters (length of "hi" minus one)
}
int replaceCount = [updatedText replaceOccurrencesOfString:@"a" withString:@" அ" options:NSCaseInsensitiveSearch range:replaceRange];
// replaceCount = [updatedText replaceOccurrencesOfString:@"aa" withString:@" ஆ" options:NSCaseInsensitiveSearch range:replaceRange];
if (replaceCount >=1) {
// update the textView's text
textView.text = updatedText;
// leave cursor at end of inserted text
endRange.location = text.length+ replaceCount*100000000; // length diff of "hello" and "hi" is 3 characters
// endRange.location;
NSRange h= endRange;
textView.selectedRange= h;
[updatedText release];
return NO;
}
[updatedText release];
return YES;
}
If I use this method, it only reads a single character and it replaces that character with a space.
If you want to replace all of “a” to “அ” and “aa” to “ஆ”
Do the following
First test for “aa”