A method to solve the problem of Chinese character display:


Add a to the local filetxt file, The format of the file is the format in which the serial number is written before and the Chinese character is written after, Then directly read the text in the local file and draw it where you need to.


-- Chinese character dictionary

    local tDictTable = {"Id", "Content"}

local DictTableFilePath =

DictTbl.txt Is the local file name

g_DictTable = GetTableFromFileWithKeyTable(DictTableFilePath, tDictTable)  




Local str = g_DictTable[1]["Content"];


Iftxt That's what it says in the document:

1   Interesting





So read itstr Namely “ Interesting”,GetTableFromFileWithKeyTable Read it outtxt File in accordance with/r/n
To divide, And put the separated string into the array, Then read through the array subscript.



-- Obtaintable: According to documents andkey list

local function GetTableFromFileWithKeyTable(file_name, keyTable)

    print("in txtConvertT")

    mainTable = {}

    mainTableIndex = 1

    fileRowIndex = 1

    -- Single row read traversal lua

    --local file = io.open(file_name);

    ---for line in file:lines() do

    -- Single row read traversal cocos

    local data = cc.FileUtils:getInstance():getStringFromFile(file_name)

    local rowArray = getAryFromRow(data, "\r\n")

    for index, line in pairs(rowArray) do


        local len = string.len(line)

        if fileRowIndex >= startRow and len > 0 then

            local subTable = {}

            rowArray = getAryFromRow(line, verStr)

            for index, value in pairs(keyTable) do

                --print("index=", index, "value=", value)

                tempValue = rowArray[index]

                --add convert to c

                --local utf8 = GBKToUtf8String(tempValue)

                subTable[value] = tempValue


            --mainTable[mainTableIndex] = subTable

            local idIndex = StringToInt(rowArray[1]);

            mainTable[idIndex] = subTable

            mainTableIndex = mainTableIndex + 1



        fileRowIndex = fileRowIndex + 1



    return mainTable




-- Obtaintable: To specify a string(tagStr) according tobystr Array after partition

function getAryFromRow(tagStr, byStr)

    rowArray = {}

    local index = 1

    local stop = 0

    local resultStr

    while stop == 0 do

        local startLocal, endLocal = string.find(tagStr, byStr)

        if startLocal == nil then

            resultStr = tagStr

            --print("resultStr2==", resultStr)

            rowArray[index] = resultStr            




        if startLocal >= 0 then

            resultStr = string.sub(tagStr, 1, startLocal - 1)

            --print("resultStr1==", resultStr)

            local tempStartLocal = startLocal + string.len(byStr)

            tagStr = string.sub(tagStr, tempStartLocal, string.len(tagStr))

            rowArray[index] = resultStr

            index = index + 1


            stop = 1



    return rowArray