Reputation: 1024
I know this is absurd but I am stuck at it
I have a filepath using fileupload in asp classic
The filepath is C:\FakePath\3.jpg
I want to retrieve it in a variable so that it would only give me 3.jpg
substring()
and substr()
doesn't include 3 I don't know why
logopath = C:\FakePath\3.jpg;
logopath = logopath.substring(10);
Upvotes: 0
Views: 224
Reputation: 4718
If you'd like to solve it in classic ASP, plesae try this.
<%
dim aryPath
aryPath = Split("C:\FakePath\3.jpg","\")
Response.Write aryPath(2)
%>
Hope it could be helpful.
Upvotes: 1
Reputation: 66388
Use such code:
function FileChanged(input) {
var fullPath = input.value;
var index = fullPath.lastIndexOf("\\");
var fileName = (index < 0) ? fullPath : fullPath.substr(index + 1);
alert(fileName);
}
The two middle lines are what you need: they will take the value after the last slash. This way it doesn't matter what is the path, it will always return only the file name.
Upvotes: 1
Reputation: 13631
logopath = encodeURIComponent( logopath ).replace( /.+FakePath%0/, '' )
'\3' is being interpreted as an octal escape sequence which points to a non-printable ASCII character.
Upvotes: 1
Reputation: 148524
try this
'C:\\FakePath\\3.jpg'.split('\\').pop();
// "3.jpg"
or (regex)
'C:\\FakePath\\3.jpg'.replace(/^.*\\/, ''); // "3.jpg"
Upvotes: 2
Reputation: 14363
In case you wish to use substring:
var str="C:\\FakePath\\3.jpg";
var imgName = str.substring(12);
Upvotes: 1