1.2k views
in Embedded Wizard Studio by
Hi Guys,

Is there a possibility to format a string like it is done with sprintf() in C? I recognized that there's the EwFormat() function available within Embedded Wizard's Runtime Environment of its Platform Package. But it seems that this function is not exposed to Chora? In particular I need to convert an integer value to a string representative as hex. Thanks!

BR,
Manuel

2 Answers

0 votes
by

Currently the programming language Chora doesn't provide such format function. The function EwFormat() exists for internal purpose within the Runtime Environment only.

To format strings:

  • use the concatenation operator plus (+)
  • convert numbers in strings with the built-in string() instant constructor

With the concatenation operator you can combine several string fragments together. With the string() instant constructor you can format integer and floating point numbers. These constructors accept additional parameters to specify more in detail the desired format operation. You can e.g. specify the number of digits in the resulting string or the positions after the point. For example, the following code formats a time string from hour, minute and second values:

var int32  hour = ...
var int32  min  = ...
var int32  sec  = ...
var string text = string( hour ) + ":" + string( min, 2 ) + ":" + string( sec, 2 );

For more details see: 'Chora User Manual' chapters: 'Binary Instant Operators' and 'Instant Constructors'

0 votes
by

Converting an integer value into a hex string is shown in the article 'Show value by HEX format'.

Embedded Wizard Website | Privacy Policy | Imprint

...