...

View Full Version : My substring() isn't working



ruffy
08-14-2008, 08:33 PM
What am not getting about substring()?
I'm trying to separate out dd and yy
from input coming in as mm/dd/yy.
(My mm is parsing out correctly).


var mm = mydate.substring(0, mydate.indexOf("/"));
var ddlength = (mydate.lastIndexOf("/")-1-mydate.indexOf("/") );
var ddstartat = (mydate.indexOf("/")+1);
var dd = mydate.substring(ddstartat, ddlength);
var yylength = (mydate.length - 1 - mydate.lastIndexOf("/"));
var yystartat = (mydate.lastIndexOf("/")+1);
var yy = mydate.substring(yystartat, yylength);

Philip M
08-14-2008, 08:44 PM
Change substring to substr. These are two different methods.


<script type = "text/javascript">
var mydate = "12/23/08"
var mm = mydate.substr(0, mydate.indexOf("/"));
var ddlength = (mydate.lastIndexOf("/")-1-mydate.indexOf("/") );
var ddstartat = (mydate.indexOf("/")+1);
var dd = mydate.substr(ddstartat, ddlength);
var yylength = (mydate.length - 1 - mydate.lastIndexOf("/"));
var yystartat = (mydate.lastIndexOf("/")+1);
var yy = mydate.substr(yystartat, yylength);

alert (mm + "/" + dd + "/" + yy)

</script>

The syntax is substr(x,y) where x is the start position of the substring and y is the length of the substring to be returned.



All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

ruffy
08-14-2008, 08:55 PM
BINGO Philip M!! Thank you my friend.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum