Click to See Complete Forum and Search --> : Splitting a string


Webskater
09-23-2003, 08:45 AM
If I have strings like:

9/2003
11/2003
04/2003

What is the easiest way to split these strings using the / as a delimiter so that I can say
var month = 9
var year = 2003

or
var month = 04
year = 2003

etc.
Thanks for any help.

Charles
09-23-2003, 08:49 AM
<script type="text/javascript">
<!--
a = '4/2003'.split('/');
month = a[0]; year = a[1];
// -->
</script>

Webskater
09-23-2003, 08:50 AM
Wow, thats what I call service. I only posted this a couple of minutes ago.
Thanks very much.

Charles
09-23-2003, 08:52 AM
Or, if you prefer:

<script type="text/javascript">
<!--
month = '4/2003'.split('/')[0];
year = '4/2003'.split('/')[1];
// -->
</script>