Lua Script 문자열 Replace 하기!

개발 2017. 10. 22. 18:29
반응형

Lua Script 에서 replace를 하려면 string.Replace 를 사용하면 됩니다.


1
string.Replace( String textString to_be_replaced, String replace_with )
cs


그러나 Lua 버전이 낮아서 Replace가 없다고 나오네요. 그래서 한번 만들어 봤습니다.


1
2
3
4
5
6
function replace(text, to_be_replaced, replace_with)
    local strFindStart, strFindEnd = string.find(text, to_be_replaced)
    if strFindStart ~= nil then
local nStringCnt = string.len(text)
     local retText = string.sub(text1, strFindStart-1) .. replace_with ..  string.sub(text, strFindEnd+1, nStringCnt)
    else
retText = text
end
return retText
end
cs

사용법 입니다.


1
2
3
local strText = "Hello# World!!"
strPrint = replace(strText, "# ""@")
 
cs


----- 결과 ----

Hello@ World!!


반응형

'개발' 카테고리의 다른 글

Lua Script(루아 스크립트) 자주쓰는 문자열 함수  (0) 2017.07.25
admin