gpt4 book ai didi

iphone - 如何在 uitextview 文本中添加自定义语言

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:15 26 4
gpt4 key购买 nike

我想使用泰米尔语键盘

功能:按A键显示அ,按AA键显示ஆ。

这是我迄今为止尝试过的。

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;
}

如果我使用此方法,它只会读取一个字符并将该字符替换为空格。

最佳答案

如果你想把所有的“a”替换成“அ”和“aa”到“ஆ”请执行下列操作第一次测试“aa”

//this will repleace all of "aa"
int replaceCount = [updatedText replaceOccurrencesOfString:@"aa" withString:@"ஆ" options:NSCaseInsensitiveSearch range:[NSMakeRange(0, updatedText.length)];

//this will repleace all of "a"
int replaceCount = [updatedText replaceOccurrencesOfString:@"a" withString:@"அ" options:NSCaseInsensitiveSearch range:[NSMakeRange(0, updatedText.length)];

关于iphone - 如何在 uitextview 文本中添加自定义语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com