Post Reply 
Bug or Not? Taking STRING of a string whilst making leading zeros
01-29-2018, 04:41 PM (This post was last modified: 01-29-2018 07:11 PM by StephenG1CMZ.)
Post: #1
Bug or Not? Taking STRING of a string whilst making leading zeros
I was trying to add some leading zeros into a string.
I discovered that if there is an unneccessary call to STRING the leading 0 doesnt appear.
Why aren't "9" and STRING("9") both of length 1, yielding 1 leading zero in the example code?
Code:

  
 
 ZEROS(NN)
 //LEADING ZEROS
 BEGIN
  //MSGBOX(NN);
  IF NN>0 THEN
   RETURN "0"+ZEROS(NN-1);
  END;
  RETURN ""; 
 END;
 
  
 EXPORT ReDIGITS (ALT )
 BEGIN
  //LOCAL NDIGITS:=2;
  LOCAL STR:="";
  LOCAL ST:="";//STRINGVERSION
   //CAS("temporary:=iquo((1*10^NDIGITS),2)");
   //ST:=CAS("string(temporary)");
   ST:="9";
   //The string version asks for leading zeros I hoped
   //but no...pad it manually 
   //STR:=CAS(format(ST,"s"+NDIGITS));
   IF ALT THEN //EXPECTED
    STR:=ZEROS(2-DIM((ST)));
   ELSE    //UNEXPECTED
    STR:=ZEROS(2-DIM(STRING(ST)));
   END;
   ST:=MID(STR+ST,TransientLEN+1);
   MSGBOX(STR);
   MSGBOX(ST);
  END; 

 EXPORT STBUG()
 BEGIN

 END;
Try with Alt 1 and Alt 0 to see the expected and erroneous output.

Is there a better way to get leading zeros in a string?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Bug or Not? Taking STRING of a string whilst making leading zeros - StephenG1CMZ - 01-29-2018 04:41 PM



User(s) browsing this thread: 1 Guest(s)