我正在执行一个简单的功能,该功能应该从阿拉伯文本中删除tashkeel,替换技术适用于英语,但不适用于阿拉伯语,您会提出什么建议?
lua代码:-
function replacePartOfString(arg,old,new)
local zzz = arg.gsub(arg, old, new)
return zzz
end
function wordLengthIgnoringTashkeel(arg)
local tashkeelArray = {"َ","ً","ُ","ٌ","ِ","ٍ","ْ","َ"}
local tempWord = arg
print("tempWord Before"..tempWord)
for x=1,#tashkeelArray do
replacePartOfString(tempWord,tashkeelArray[x],"")
end
print("tempWord After"..tempWord)
end
结果
tempWord After اليَوْمَ tempWord After اليَوْمَ
而预期的结果
预期结果
tempWord之后اليَوْمْ tempWord之后اليَوَمَ
最佳答案
这有效
function replacePartOfString(arg,old,new)
return arg.gsub(arg, old, new)
end
function wordLengthIgnoringTashkeel(arg)
local tashkeelArray = {"َ","ً","ُ","ٌ","ِ","ٍ","ْ","َّ"}
local tempWord = arg
for x=1,#tashkeelArray do
tempWord = replacePartOfString(tempWord,tashkeelArray[x],"")
end
return #tempWord
end