Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript strings

Posted on 2014-02-06
4
Medium Priority
?
369 Views
Last Modified: 2014-02-06
Hi

I have a string:

url("file:///C:/Users/langlp/Desktop/BMW%20demo/img/36_bw.jpg")


I want to get the image name "36_bw.jpg". How do i get this with javascript?

Thanks
0
Comment
Question by:coolispaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Accepted Solution

by:
stergium earned 2000 total points
ID: 39838707
hello

var a='url("file:///C:/Users/langlp/Desktop/BMW%20demo/img/36_bw.jpg")';
var b=a.indexOf(')');
var c=a.lastIndexOf('/');
console.log(a.substring((c+1),(b-1)));

Open in new window


change the console log to whatever you need. hope that helps
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39838786
Test page : http://jsfiddle.net/b3L5z/

var img = str.match(/img\/([^.]*\.jpg)/).pop();

Open in new window

0
 

Author Comment

by:coolispaul
ID: 39838850
perfect thanks guys
0
 
LVL 7

Expert Comment

by:Alex_W
ID: 39838914
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question