如何在 Lua 中删除字符串中的阿拉伯语调音符号?

我正在编写一个简单的函数,应该从阿拉伯文本中删除调音符号,替换技术对英文有效,但对阿拉伯文无效,你有什么建议?

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 Beforeاليَوْمَ tempWord Afterاليَوْمَ

而期望的结果是

期望的结果

tempWord Beforeاليَوْمَ tempWord Afterاليوم

点赞
用户5312361
用户5312361
这个函数有效

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

```

2016-09-17 18:04:39
用户3041972
用户3041972
function wordLengthIgnoringTashkeel(arg)
local tashkeelArray = {"َ","ً","ُ","ٌ","ِ","ٍ","ْ","َ"}

local tempWord = arg

print("tempWord Before"..tempWord)
for x=1,#tashkeelArray do
tempWord = string.gsub(tempWord,tashkeelArray[x],"")
end
print("tempWord After"..tempWord)
end

wordLengthIgnoringTashkeel("يَوْمَ")
function wordLengthIgnoringTashkeel(arg)
local tashkeelArray = {"ÙŽ","Ù‹","ُ","ÙŒ","ِ","ٍ","Ù’","ÙŽ"} -- 定义了一个包含了特殊符号的数组

local tempWord = arg -- 将参数赋值给tempWord

print("tempWord Before"..tempWord) -- 输出当前的tempWord

-- 使用for循环,将特殊符号替换为空字符串
for x=1,#tashkeelArray do
tempWord = string.gsub(tempWord,tashkeelArray[x],"")
end

print("tempWord After"..tempWord) -- 输出替换后的tempWord
end

wordLengthIgnoringTashkeel("يَوْمَ") -- 调用函数并传入参数"يَوْمَ"
2016-09-18 08:15:06
用户11208345
用户11208345

这段代码或许可以帮到你,它对于一个文件可行:

perl  -CS -pe 's/[\x{064B}-\x{0650}]|[\x{0618}-\x{061A}]|[\x{0652}-\x{0653}]|[\x{0652}-\x{0653}]+//g' < "$f" > "$f.txt" ;

对于一个文件夹下的所有文件:

for f in *.txt; do

perl  -CS -pe 's/[\x{064B}-\x{0650}]|[\x{0618}-\x{061A}]|[\x{0652}-\x{0653}]|[\x{0652}-\x{0653}]+//g' < "$f" > "$f.txt" ;

done

谢谢。

2019-05-19 01:08:27