- C++
string getBaseName(string path) {
int l = path.length();
int i;
for(i = l-1; i >=0; i--) {
if(path[i] == '/') break;
}
return path.substr(i+1, l-i-1);
}
- python
path='/home/lwd/t.txt'
basename=path.split('/')[-1]
string getBaseName(string path) {
int l = path.length();
int i;
for(i = l-1; i >=0; i--) {
if(path[i] == '/') break;
}
return path.substr(i+1, l-i-1);
}
path='/home/lwd/t.txt'
basename=path.split('/')[-1]