DOF/sqr/Core/BaseTool/String.nut

37 lines
1.0 KiB
Plaintext
Raw Normal View History

2024-12-11 15:08:57 +08:00
/*
文件名:String.nut
路径:Core/BaseTool/String.nut
创建日期:2024-11-28 23:05
文件用途:
*/
class String {
//将含有../的路径转为真实路径
function RegRealPath(Path) {
if (Path.find("../") != null) {
while (true) {
local rbuf = regexp("[^/]+/../");
local Ret = rbuf.capture(Path);
if (Ret) {
Path = Path.slice(0, Ret[0].begin) + Path.slice(Ret[0].end);
} else {
return Path;
}
}
}
return Path;
}
2025-02-20 13:53:36 +08:00
function ReplaceString(input, pattern, replacement) {
local rbuf = typeof pattern == "string" ? regexp(pattern) : pattern;
while (true) {
local result = rbuf.capture(input);
if (!result) break;
local begin = result[0].begin;
local end = result[0].end;
input = input.slice(0, begin) + replacement + input.slice(end);
}
return input;
}
2024-12-11 15:08:57 +08:00
}