Announcement

Collapse
No announcement yet.

use String.split() - how?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • use String.split() - how?

    Hello,

    how can I split the incoming close() ?

    If I get the ES#F, I need the value befor the dot and separately behind (e.g. 1275.75 split into 1275 an into 75)

    How can I do it?

    I tryed this, but it doesn't work



    var vk=0;
    var nk=0;
    tmp=0,
    tmp1=0;

    function main () {
    tmp=close(); // incoming ES#F
    tmp1 = tmp.split("."); // split at the dot
    vk = tmp1[0];
    nk = tmp1[1];
    debugPrint(" "+close()+"; "+tmp+"; "+tmp1+"; "+vk+"; "+nk+" \n");

    }

    need a littel help, Torso

  • #2
    Hi Torso,

    The problem you were having was that you were trying to split a number. The split command is an operator that only applies to a string. I rewrote your code a bit, incorporating a step to convert the number to a string, then I added several additional steps which show an alternate method and some other commands. I hope this helps.

    PHP Code:
    function main () {
     if((
    getBarState() == BARSTATE_NEWBAR)){
      var 
    close(0);
      var 
    tmp=""+c// incoming ES#F
      
    var tmp1 tmp.split("."); // split at the dot
      
    var vk tmp1[0];
      var 
    nk tmp1[1];
      
    debugPrintln("8: "+c+"; "+tmp+"; "+tmp1+"; "+vk+"; "+nk);
      var 
    tmp2 = new Array();
      
    tmp2[0] = Math.floor(c);
      
    tmp2[1] = c-tmp2[0];
      
    debugPrintln("12: tmp2 = "+tmp2+" typeof(tmp2[0]) = "+typeof(tmp2[0])+" typeof(tmp2[1]) = "+typeof(tmp2[1]));
      
    tmp2[0]+="";
      
    tmp2[1]+="";
      
    debugPrintln("15: tmp2 = "+tmp2+" typeof(tmp2[0]) = "+typeof(tmp2[0])+" typeof(tmp2[1]) = "+typeof(tmp2[1]));
     }

    Comment

    Working...
    X