View Full Version : extract a string from a string
Tails
01-29-2003, 07:50 PM
This is a silly question, but I have to know. How can you cut a string at a certain point? For example, I want to detect the directory that a file is loaded in with JS. window.location shows the path and file at the end. The only way I know is with substrings and what do you do when you don't know the exact length of the path or file? I think this is with slice. I don't know many of such methods like that. I only know what was covered in the tutorials at htmlgoodies.com and a few things here.
Tails
01-29-2003, 08:06 PM
Never mind, I found a similar question here http://www.codingforums.com/showthread.php?threadid=13800
on the same page of recent stuff. Aww come on, I'm sure it's happened to everyone atleast once.
whammy
01-30-2003, 12:55 AM
Yeah, that thread should do it, although you could use a number of different techniques to accomplish the same thing, like the split() function...
Tails
02-01-2003, 04:58 PM
I think you're right. Can you give me a quick definition and example of the split method?
whammy
02-01-2003, 05:19 PM
<script type="text/javascript">
<!--
var mystring = "This,is,a,test!";
var w = mystring.split(",");
document.write(w.join(" "));
// -->
</script>
Tails
02-01-2003, 05:46 PM
Thanks, I'll try that out.:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.