joshuamil

ArraySplice()

Dec 12th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfscript>
  2. function ArraySplice(array,from,to){
  3.     try{
  4.         if(ArrayLen(arguments)==3){
  5.             var append = "";
  6.         }else{
  7.             var append = arguments[4];
  8.         }
  9.        
  10.         var newArray = array;
  11.        
  12.         for(var i=from;i<to;i++){
  13.             ArrayDeleteAt(newArray,from);
  14.         }
  15.         for(var i=1;i<=ListLen(append);i++){
  16.             ArrayAppend(newArray,ListGetAt(append,i));
  17.         }
  18.        
  19.         return newArray;
  20.     }
  21.     catch(Any e){
  22.         return e;
  23.     }
  24.    
  25. }
  26.  
  27.  
  28. foo = ["A","B","C","D"];
  29.  
  30. bar1 = ArraySplice(foo,2,4,"A,B,C");
  31. bar2 = ArraySplice(foo,1,4);
  32. </cfscript>
  33.  
  34. <!--- DEBUG --->
  35. <cfdump var="#bar1#" label="Debug">
  36. <cfdump var="#bar2#" label="Debug">
  37. <cfabort>
Advertisement
Add Comment
Please, Sign In to add comment