A method to solve the problem of Chinese character display :

 

Add a to the local file txt 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 it needs to be used .

 

-- Chinese character dictionary

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

local DictTableFilePath =
cc.FileUtils:getInstance():fullPathForFilename("Config/DictTbl.txt")

DictTbl.txt Is the local file name

g_DictTable = GetTableFromFileWithKeyTable(DictTableFilePath, tDictTable)  

 

 

 

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

 

If txt That's what it says in the document :

1   interesting

.

.

.

 

So read it str namely “ interesting ”,GetTableFromFileWithKeyTable Read it out txt Document as per /r/n
To split , And put the separated string into the array , Then read through the array subscript .

 

 

-- obtain table: According to documents and key 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

            end

            --mainTable[mainTableIndex] = subTable

            local idIndex = StringToInt(rowArray[1]);

            mainTable[idIndex] = subTable

            mainTableIndex = mainTableIndex + 1

        else

        end

        fileRowIndex = fileRowIndex + 1

    end

 

    return mainTable

End

 

--(table)getAryFromRow(tagStr,byStr)

-- obtain table: To specify a string (tagStr) according to bystr 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            

            break

            else

        end

        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

            else

            stop = 1

            end

    end

    return rowArray

end