如何隔离由Lua中的空格分隔的非英语单词? [英] How to isolate non english words separated by spaces in Lua?

查看:230
本文介绍了如何隔离由Lua中的空格分隔的非英语单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个字符串

 你好,这是一些行aa。 

如何将它切成像这样的数组?

 您好
在那里,
这个

一些
line-aa。

这是我到目前为止所尝试过的内容

< pre $($ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'
table.insert(list,k)
end
return list
end

local sentence =مرحبايااخوتي
print( sliceSpaces)
print(sliceSpaces(句子))

对于英文文本,但不是用于阿拉伯文,我怎样才能使它成为阿拉伯文呢?

解析方案

是字节序列,而不是Unicode字符。 %w 模式匹配字母数字字符,但它仅适用于ASCII。



改为使用%S 匹配一个非空白字符:

  for k in arg:gmatch %S +)do 


I have this string

"Hello there, this is some line-aa."

how to slice it into an array like this?

Hello
there,
this
is
some
line-aa.

this is what I have tried so far

function sliceSpaces(arg)
  local list = {}
  for k in arg:gmatch("%w+") do
    print(k)
    table.insert(list, k)
  end
  return list
end

local sentence = "مرحبا يا اخوتي"
print("sliceSpaces")
print(sliceSpaces(sentence))

this code works for English text, but not for arabic, how can I make it work for arabic too?

解决方案

Lua strings are sequences of bytes, not Unicode characters. The pattern %w matches alphanumeric characters, but it applies to ASCII only.

Instead, use %S to match a non-whitespace character:

for k in arg:gmatch("%S+") do

这篇关于如何隔离由Lua中的空格分隔的非英语单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆