Solved

javascript strings

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now