Is there a way to format a string within Chora like done with sprintf() in C?

765 views
asked Jun 2, 2016 in Embedded Wizard Studio by Manuel Melic
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
answered Jun 2, 2016 by Paul Banach

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
answered Nov 2, 2016 by Manfred Schweyer

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

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...