Geoff said:
On Wed, 14 Sep 2005 12:26:26 +0200, ASM
Geoff
Thanks for this Stephane - I have it working but perhaps you could
explain hwo it works!?
it works with Javascript
what don't you understand ?
var S = 'stephane';
// position of 'n' in S :
p = S.indexOf('n');
// position of 'e' in S :
p1 = S.indexOf('e');
// position of 'e' in S :
p2 = S.lastIndexOf('e');
alert('position of :\n n = '+p+'\n1st e = '+p1+'\n2nd e = '+p2);
// extract 'ne' from S :
str1 = S.substring(p);
// extract 'ste' from S :
str2 = S.substring(0, p1+1);
// extract 'phane' from S :
str3 = S.substring(p1+1);
/* stringToGet = originalString.substring(i_1, i_2)
*
* i_1 = index in originalString ==> will be 1st of stringToGet
* i_2 = index in originalString ==> will be last of stringToGet
* if i_2 is obmited, stringToGet finishes with end of originalString
*/
alert('extractions :\n ne = '+str1+'\n ste = '+str2+'\nphane = '+str3);
// delete first and/or last space if existing in 'fred'
// create array with each indidual number from 'fred'
// using function : split(separator)
// will troncatenate the string with bits separed by separator
// Here, separator is a white space ==> ' '
// a counter set to zero
// from a value = 0 to a value = precedent array length
// with a variation = to 2
// fred's element of row = j becomes
// fred's element of row = i plus his next fellow
fred[j] = fred+' '+fred[i+1];
// increase of 1 the counter 'j'
// and rebegin with new values of 'j' and of 'i'
// because fred is now less large
// we tell him how long it is
// (we know this length which was given by last value of 'j')
// exactly same as deleting last survivors old elements
// we did get fred = ('0 -10' , '5 6')
// each element of fred will now be broken in 2 parts
// that's to say we create a secondary array for each element
// secondary array
for(var i=0;i<fred.length;i++) {
fred = fred.split(' ');
/* fred is now composed with :
* fred[0][0] = '0';
* fred[0][1] = '-10';
* fred[1][0] = '5';
* fred[1][0] = '6';
*
*/
// verification
alert('array = '+fred+'\nfred[0][1] = '+fred[0][1]);
</script>
</html>