[Scilab-users] String and integer

classic Classic list List threaded Threaded
5 messages Options
paul francedixhuit paul francedixhuit
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] String and integer

Hi all

In ordre to change files names, I need to convert integers into strings but with zeros prior to it

Example if i=1 i need 0001 and not 1

I don't know how to use something like "%4d" with "string"

Thanks

Paul

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
David Chèze David Chèze
Reply | Threaded
Open this post in threaded view
|

Re: String and integer

Hi Paul,

 

--> msprintf("%04d",3)

ans  =

 

  "0003"

 

 

 

David

 

De : users <[hidden email]> De la part de paul francedixhuit
Envoyé : vendredi 20 novembre 2020 14:49
À : Users mailing list for Scilab <[hidden email]>
Objet : [Scilab-users] String and integer

 

Hi all

 

In ordre to change files names, I need to convert integers into strings but with zeros prior to it

 

Example if i=1 i need 0001 and not 1

 

I don't know how to use something like "%4d" with "string"

 

Thanks

 

Paul


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
jbaudais jbaudais
Reply | Threaded
Open this post in threaded view
|

Re: String and integer

In reply to this post by paul francedixhuit
Hi,
  A solution, of course not the best,
--> if i<10, s=msprintf("000%d",i) end
with iteration for high number, or with 3-floor(log10(i)) added zeros?

--Jean-Yves

----- Original Message -----
> From: "paul francedixhuit" <[hidden email]>
> To: "Users mailing list for Scilab" <[hidden email]>
> Sent: Friday, 20 November, 2020 14:48:46
> Subject: [Scilab-users] String and integer

> Hi all
>
> In ordre to change files names, I need to convert integers into strings but with
> zeros prior to it
>
> Example if i=1 i need 0001 and not 1
>
> I don't know how to use something like "%4d" with "string"
>
> Thanks
>
> Paul
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users

--
--
Jean-Yves Baudais
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Denis Crété Denis Crété
Reply | Threaded
Open this post in threaded view
|

Re: String and integer

In reply to this post by paul francedixhuit

Hello 

msprintf(‘%04d’,1) seems to do the job

HTH

Denis

De : users <[hidden email]> De la part de paul francedixhuit
Envoyé : vendredi 20 novembre 2020 14:49
À : Users mailing list for Scilab <[hidden email]>
Objet : [Scilab-users] String and integer

 

Hi all

 

In ordre to change files names, I need to convert integers into strings but with zeros prior to it

 

Example if i=1 i need 0001 and not 1

 

I don't know how to use something like "%4d" with "string"

 

Thanks

 

Paul


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Denis Crété
paul francedixhuit paul francedixhuit
Reply | Threaded
Open this post in threaded view
|

Re: String and integer

In reply to this post by David Chèze
Based on your advices, I've fix my issue.

Thanks

Paul

###############################################
i = 1
FileName = "MyFile"
// Previously
NewFileName1 = FileName + string(i)
// Now
NewFileName2 = FileName + msprintf("%.4d",i)
i = 666
NewFileName3 = FileName + msprintf("%.4d",i)


Le ven. 20 nov. 2020 à 15:43, CHEZE David 227480 <[hidden email]> a écrit :

Hi Paul,

 

--> msprintf("%04d",3)

ans  =

 

  "0003"

 

 

 

David

 

De : users <[hidden email]> De la part de paul francedixhuit
Envoyé : vendredi 20 novembre 2020 14:49
À : Users mailing list for Scilab <[hidden email]>
Objet : [Scilab-users] String and integer

 

Hi all

 

In ordre to change files names, I need to convert integers into strings but with zeros prior to it

 

Example if i=1 i need 0001 and not 1

 

I don't know how to use something like "%4d" with "string"

 

Thanks

 

Paul

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users