?
Solved

javascript strings

Posted on 2014-02-06
4
Medium Priority
?
360 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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)
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

801 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