Using custom format strings to format double and string outputs

ID: 1471

See: EvalStr
				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineVariable("num = 42");
uc.DefineVariable("txt = 'Hello'");

// Using modern format strings with alignment and casting
Console.WriteLine(uc.EvalStr("num", "Result = Format('--{:6}--', double(Result))"));

// Using multiple placeholder references
Console.WriteLine(uc.EvalStr("txt", "Result = Format('{0}! and {0}', Result)"));
				
			
--    42--
Hello! and Hello
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineVariable("num = 42");
   uc.DefineVariable("txt = 'Hello'");

   // Using modern format strings with alignment and casting
   cout << uc.EvalStr("num", "Result = Format('--{:6}--', double(Result))") << endl;

   // Using multiple placeholder references
   cout << uc.EvalStr("txt", "Result = Format('{0}! and {0}', Result)") << endl;
}
				
			
--    42--
Hello! and Hello
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineVariable("num = 42")
      uc.DefineVariable("txt = 'Hello'")
      
      '// Using modern format strings with alignment and casting
      Console.WriteLine(uc.EvalStr("num", "Result = Format('--{:6}--', double(Result))"))
      
      '// Using multiple placeholder references
      Console.WriteLine(uc.EvalStr("txt", "Result = Format('{0}! and {0}', Result)"))
   End Sub
End Module
				
			
--    42--
Hello! and Hello