Solved

javascript strings

Posted on 2014-02-06
4
355 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

726 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