lua: 截取字符串/home/root/test/123:输出结果为123 ,怎么弄呢?

如题所述

local s = "/home/root/test/123"
print(string.match(s,".+/(.+)"))
匹配出最后一次/之后的内容
我不确定你的字符串是
/home/root/test/123:

还是
/home/root/test/123

如果是
/home/root/test/123:的话就是

local s = "/home/root/test/123:"
print(string.match(s,".+/(.+):"))
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-23
String strs = "/home/root/test/123";
int last = strs.lastIndexOf("/");
String str = strs.substring(last+1, strs.length()); //不带 / 就让last加1 ,带斜杠就不用加
System.out.println(str);

楼上们貌似写的很高深,我不怎么能看懂! 没用过。。。
第2个回答  2019-02-20
一二三楼依次使用Lua C Java
第3个回答  2012-11-21
#include<string.h>
#include<stdio.h>
void main()
{
char str[]= "/home/root/test/123";
printf("%s\n", strrchr(str, '/') + 1 );
}
相似回答