函数:reTxtUtf8 过滤文本前的 UTF8-BOM 内容

函数名称:过滤 UTF8-BOM

函数功能:过滤文本前的 UTF8-BOM 内容

TSLib 版本:仅支持 v1.2.8 及其以上版本

函数方法

str2 = reTxtUtf8(str1)

参数 类型 必填 说明
str1 string 需要过滤 UTF8-BOM 字符的内容
返回值 类型 说明
str2 string 过滤 UTF8-BOM 后的内容

函数用例

require "TSLib"
local ts = require("ts")
function downFile(url, path)
    status, headers, body = ts.httpGet(url)
    if status == 200 then
        file = io.open(path, "wb")
        if file then
            file:write(body)
            file:close()
            return status;
        else
            return -1;
        end
    else
        return status;
    end
end
downFile("https://video.touchsprite.com/公开分享/cs.txt", userPath().."/res/cs.txt")
local file = io.open(userPath().."/res/cs.txt",r)
if type(file) ~= "boolean"  then 
    a=file:read("*a")
    --文件内容
    dialog("文件内容:"..a,3)
    --未过滤前的字符串长度
    dialog("未过滤的字符串长度:"..string.len(a),3)
    --过滤后的字符串长度
    str = reTxtUtf8(a,3)
    dialog("过滤后的字符串长度:"..string.len(str),3)
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""