跳转到内容

模組討論:String

页面内容不支持其他语言。
维基百科,自由的百科全书

这是本页的一个历史版本,由Great Brightstar留言 | 贡献2018年1月12日 (五) 07:54 編輯請求编辑。这可能和当前版本存在着巨大的差异。


Great Brightstar在话题“編輯請求”中的最新留言:7年前

編輯請求

User:Manchiu

請求新增一個切割字串函數,已在Module:Chemicals中使用(Special:Diff/47444448函式原型: string[] str::split(string,string))
Module:Chemicals應該是要放置化學相關函數
而字串相關函數應置於此,因此申請編輯請求
function str.split(inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local result={} ; i=1
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                result[i] = str
                i = i + 1
        end
        return result
end

lua沒有函數載入順序問題,以上函式放在任意位置皆可 -- 宇帆(明年二月加入維基將滿十周年!留言·歡迎簽到·聯絡2017年12月19日 (二) 17:55 (UTC)回复

split

function prototypt(by c++):string[] 模块::String::str::split ( const string inputstr, const string sep );
This function splits a String into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

Usage:

str.split( target_string, separator_string )

Parameters:

inputstr target_string
The string to split
sep separator_string
Specifies the string which denotes the points at which each split should occur.