我正在用lua写一些东西,我遇到了问题。 我知道您可以使用io.popen()
从lua执行cmd命令我做了类似
的事情function move(from, to)
io.popen(string.format([==[move %s %s]==], from, to))
end
但是我遇到了一个问题,因为我是德国人,我的文件有时会包含ö,ä,ü或ß,然后就会中断。
如何让它与所有德国角色一起使用?
我搜索并找到了一个可能的解决方案io.popen("chcp 1252")
,但我无法让它工作。
编辑:我正在使用Window 7。
答案 0 :(得分:0)
我尝试了your_filename:fromutf8()
,无论我做了什么都没有用。
我也尝试了chcp 1252 & echo weiß
并且它没有改变任何东西,但我最终想出来了。
local ersetzen = {
[142] = string.char(196), --Ä
[132] = string.char(228), --ä
[153] = string.char(214), --Ö
[148] = string.char(246), --ö
[154] = string.char(220), --Ü
[129] = string.char(252), --ü
[225] = string.char(223), --ß
}
local function split(...)
local output = {}
for i = 1, string.len(...) do
output[i] = string.sub(..., i, i)
end
return output
end
local function konvertieren(datei)
local a = split(datei)
local rest = {}
for k, v in pairs(a) do
table.insert(rest, (ersetzen[string.byte(v)] or v))
end
return table.concat(rest)
end
可能有一个较短的方法,但这对我有用。
答案 1 :(得分:0)
local cp850_to_cp1252 = {
['\128'] = '\199',
['\129'] = '\252',
['\130'] = '\233',
['\131'] = '\226',
['\132'] = '\228',
['\133'] = '\224',
['\134'] = '\229',
['\135'] = '\231',
['\136'] = '\234',
['\137'] = '\235',
['\138'] = '\232',
['\139'] = '\239',
['\140'] = '\238',
['\141'] = '\236',
['\142'] = '\196',
['\143'] = '\197',
['\144'] = '\201',
['\145'] = '\230',
['\146'] = '\198',
['\147'] = '\244',
['\148'] = '\246',
['\149'] = '\242',
['\150'] = '\251',
['\151'] = '\249',
['\152'] = '\255',
['\153'] = '\214',
['\154'] = '\220',
['\155'] = '\248',
['\156'] = '\163',
['\157'] = '\216',
['\158'] = '\215',
['\159'] = '\131',
['\160'] = '\225',
['\161'] = '\237',
['\162'] = '\243',
['\163'] = '\250',
['\164'] = '\241',
['\165'] = '\209',
['\166'] = '\170',
['\167'] = '\186',
['\168'] = '\191',
['\169'] = '\174',
['\170'] = '\172',
['\171'] = '\189',
['\172'] = '\188',
['\173'] = '\161',
['\174'] = '\171',
['\175'] = '\187',
['\176'] = '?',
['\177'] = '?',
['\178'] = '?',
['\179'] = '?',
['\180'] = '?',
['\181'] = '\193',
['\182'] = '\194',
['\183'] = '\192',
['\184'] = '\169',
['\185'] = '?',
['\186'] = '?',
['\187'] = '?',
['\188'] = '?',
['\189'] = '\162',
['\190'] = '\165',
['\191'] = '?',
['\192'] = '?',
['\193'] = '?',
['\194'] = '?',
['\195'] = '?',
['\196'] = '?',
['\197'] = '?',
['\198'] = '\227',
['\199'] = '\195',
['\200'] = '?',
['\201'] = '?',
['\202'] = '?',
['\203'] = '?',
['\204'] = '?',
['\205'] = '?',
['\206'] = '?',
['\207'] = '\164',
['\208'] = '\240',
['\209'] = '\208',
['\210'] = '\202',
['\211'] = '\203',
['\212'] = '\200',
['\213'] = '?',
['\214'] = '\205',
['\215'] = '\206',
['\216'] = '\207',
['\217'] = '?',
['\218'] = '?',
['\219'] = '?',
['\220'] = '?',
['\221'] = '\166',
['\222'] = '\204',
['\223'] = '?',
['\224'] = '\211',
['\225'] = '\223',
['\226'] = '\212',
['\227'] = '\210',
['\228'] = '\245',
['\229'] = '\213',
['\230'] = '\181',
['\231'] = '\254',
['\232'] = '\222',
['\233'] = '\218',
['\234'] = '\219',
['\235'] = '\217',
['\236'] = '\253',
['\237'] = '\221',
['\238'] = '\175',
['\239'] = '\180',
['\240'] = '\173',
['\241'] = '\177',
['\242'] = '?',
['\243'] = '\190',
['\244'] = '\182',
['\245'] = '\167',
['\246'] = '\247',
['\247'] = '\184',
['\248'] = '\176',
['\249'] = '\168',
['\250'] = '\183',
['\251'] = '\185',
['\252'] = '\179',
['\253'] = '\178',
['\254'] = '?',
['\255'] = '\160',
}
function string.from850(filename)
return (filename:gsub(".", cp850_to_cp1252))
end
用法:your_filename:from850()