Category: JavaScript — admin @ 12:11 pm — Comments (0)

Initial conditions:

var fullPath = 'folder1/folder2/folder3/filename.jpg';

What need get:

filename.jpg


Code example:

var fileName = '';
if (fullPath) {
    var startIndex = (fullPath.indexOf('\\') >= 0
        ? fullPath.lastIndexOf('\\')
        : fullPath.lastIndexOf('/'))
    ;
    var fileName = fullPath.substring(startIndex);
    if (fileName.indexOf('\\') === 0 || fileName.indexOf('/') === 0) {
        fileName = fileName.substring(1);
    }
}

Sorry, no comments yet.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
This is where you type your comments. 
Remember my information for the next time I visit.