EvaluateStrMethod

Applies to:Fast Math Parser
Class:uCalc.ParsedExpr
Rapidly evaluates an expression of any data type that was parsed with Parse or passed By Expression returning a string
Syntax
EvaluateStr()
Remarks
EvaluateStr is similar to Evaluate. However, EvaluateStr returns a value as a string. Unlike Evaluate, which can only return a floating point value, EvaluateStr can return a value of any data type. Non-string values are converted to a string before being returned.

Example 1: displaying each character of a string on a separate line

Dim MyString As string
Console.Write("Enter an expression (Ex: 'This is a Test'): ")
MyString = Console.ReadLine()
Dim VariableX = uc.DefineVariable("x As Int32")
Dim MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString)
Dim ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)")
Dim StrLength = uc.Eval("Length(MyStringVar)")

Dim x As Int32
for x = 0 To StrLength-1
   VariableX.SetVariableValueInt32(x)
   Console.WriteLine(ParsedExpr.EvaluateStr())
Next
' Output
' T
' h
' i
' s
'  
' i
' s
'  
' a
'  
' T
' e
' s
' t

          

string MyString;
Console.Write("Enter an expression (Ex: 'This is a Test'): ");
MyString = Console.ReadLine();
var VariableX = uc.DefineVariable("x As Int32");
var MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
var ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
var StrLength = uc.Eval("Length(MyStringVar)");

for (Int32 x = 0; x <= StrLength-1; x++) {
   VariableX.SetVariableValueInt32(x);
   Console.WriteLine(ParsedExpr.EvaluateStr());
}
// Output
// T
// h
// i
// s
//  
// i
// s
//  
// a
//  
// T
// e
// s
// t

          

      Write('Enter an expression (Ex: "This is a Test"): ')
MyString = ReadLn();
//var VariableX = uc.DefineVariable('x As Int32');
//var MyStringVar = uc.DefineVariable('MyStringVar As String = ' + MyString);
//var ParsedExpr = uc.Parse('Substr(MyStringVar, x, 1)');
//var StrLength = uc.Eval('Length(MyStringVar)');

      for x := 0 to StrLength-1 do
begin
   VariableX.SetVariableValueInt32(x);
         WriteLn(ParsedExpr.EvaluateStr());
End;
      // Output
// T
// h
// i
// s
//  
// i
// s
//  
// a
//  
// T
// e
// s
// t

          

string MyString;      
cout << "Enter an expression (Ex: 'This is a Test'): " << endl;
cin >> MyString; // Ex: 'This is a Test'
auto VariableX = uc.DefineVariable("x As Int32");
auto MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
auto ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
auto StrLength = uc.Eval("Length(MyStringVar)");

for (int x = 0; x <= StrLength-1; x++) {
   VariableX.SetVariableValueInt32(x);
   cout << ParsedExpr.EvaluateStr() << endl;
}
// Output
// T
// h
// i
// s
//  
// i
// s
//  
// a
//  
// T
// e
// s
// t

          

string ^ MyString;
Console::Write("Enter an expression (Ex: 'This is a Test'): ");
MyString = Console::ReadLine();
auto VariableX = uc.DefineVariable("x As Int32");
auto MyStringVar = uc.DefineVariable("MyStringVar As String = " + MyString);
auto ParsedExpr = uc.Parse("Substr(MyStringVar, x, 1)");
auto StrLength = uc.Eval("Length(MyStringVar)");

for (int x = 0; x <= StrLength-1; x++) {
   VariableX.SetVariableValueInt32(x);
   Console::WriteLine(ParsedExpr.EvaluateStr());
}
// Output
// T
// h
// i
// s
//  
// i
// s
//  
// a
//  
// T
// e
// s
// t

          
Example 2: Displaying a different complex number result for each value of x based on the expression parsed with Parse

Dim x As double
Dim VariableX = uc.DefineVariable("x")
Dim Expression As string
Console.Write("Enter an expression (Ex: x * #i + 5): ")
Expression = Console.ReadLine()

Dim ParsedExpr = uc.Parse(Expression, "Complex"): ' NOTE: EvaluateStr works with any data type;

for x = 1 To 10
   VariableX.SetVariableValue(x)
   Console.WriteLine("x = " + x + "  Result = " + ParsedExpr.EvaluateStr())
Next
' Output
' x = 1  Result = 5+1i
' x = 2  Result = 5+2i
' x = 3  Result = 5+3i
' x = 4  Result = 5+4i
' x = 5  Result = 5+5i
' x = 6  Result = 5+6i
' x = 7  Result = 5+7i
' x = 8  Result = 5+8i
' x = 9  Result = 5+9i
' x = 10  Result = 5+10i

ParsedExpr.Release()
VariableX.Release()

          

double x;
var VariableX = uc.DefineVariable("x");
string Expression;
Console.Write("Enter an expression (Ex: x * #i + 5): ");
Expression = Console.ReadLine();

var ParsedExpr = uc.Parse(Expression, "Complex"); // NOTE: EvaluateStr works with any data type;

for (x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   Console.WriteLine("x = " + x + "  Result = " + ParsedExpr.EvaluateStr());
}
// Output
// x = 1  Result = 5+1i
// x = 2  Result = 5+2i
// x = 3  Result = 5+3i
// x = 4  Result = 5+4i
// x = 5  Result = 5+5i
// x = 6  Result = 5+6i
// x = 7  Result = 5+7i
// x = 8  Result = 5+8i
// x = 9  Result = 5+9i
// x = 10  Result = 5+10i

ParsedExpr.Release();
VariableX.Release();

          

//var x: Double;
//var VariableX = uc.DefineVariable('x');
      Write('Enter an expression (Ex: x * #i + 5): ')
Expression = ReadLn();

//var ParsedExpr = uc.Parse(Expression, 'Complex'); // NOTE: EvaluateStr works with any data type;

      for x := 1 to 10 do
begin
   VariableX.SetVariableValue(x);
         WriteLn('x = ' + x + '  Result = ' + ParsedExpr.EvaluateStr());
End;
      // Output
// x = 1  Result = 5+1i
// x = 2  Result = 5+2i
// x = 3  Result = 5+3i
// x = 4  Result = 5+4i
// x = 5  Result = 5+5i
// x = 6  Result = 5+6i
// x = 7  Result = 5+7i
// x = 8  Result = 5+8i
// x = 9  Result = 5+9i
// x = 10  Result = 5+10i

      ParsedExpr.Release();
      VariableX.Release();

          

double x;
auto VariableX = uc.DefineVariable("x");
string Expression;      
cout << "Enter an expression (Ex: x * #i + 5): " << endl;
cin >> Expression; // Ex: x * #i + 5

auto ParsedExpr = uc.Parse(Expression, "Complex"); // NOTE: EvaluateStr works with any data type;

for (x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   cout << "x = " << x << "  Result = " << ParsedExpr.EvaluateStr() << endl;
}
// Output
// x = 1  Result = 5+1i
// x = 2  Result = 5+2i
// x = 3  Result = 5+3i
// x = 4  Result = 5+4i
// x = 5  Result = 5+5i
// x = 6  Result = 5+6i
// x = 7  Result = 5+7i
// x = 8  Result = 5+8i
// x = 9  Result = 5+9i
// x = 10  Result = 5+10i

ParsedExpr.Release();
VariableX.Release();

          

double x;
auto VariableX = uc.DefineVariable("x");
string ^ Expression;
Console::Write("Enter an expression (Ex: x * #i + 5): ");
Expression = Console::ReadLine();

auto ParsedExpr = uc.Parse(Expression, "Complex"); // NOTE: EvaluateStr works with any data type;

for (x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   Console::WriteLine("x = " + x + "  Result = " + ParsedExpr.EvaluateStr());
}
// Output
// x = 1  Result = 5+1i
// x = 2  Result = 5+2i
// x = 3  Result = 5+3i
// x = 4  Result = 5+4i
// x = 5  Result = 5+5i
// x = 6  Result = 5+6i
// x = 7  Result = 5+7i
// x = 8  Result = 5+8i
// x = 9  Result = 5+9i
// x = 10  Result = 5+10i

ParsedExpr.Release();
VariableX.Release();

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="EvaluateStr")> _

Private Function EvaluateStr__(ByVal ExprHandle As IntPtr) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="EvaluateStr")]

protected static extern  IntPtr EvaluateStr_(IntPtr ExprHandle);
            
{DLLImport}function EvaluateStr__(ExprHandle: System.Pointer):  PAnsiChar; cdecl; external uCalcDLL name 'EvaluateStr';

            
typedef const char * (* __EvaluateStr)(void *ExprHandle); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "EvaluateStr")]

static STR_RETURN EvaluateStr_(void *  ExprHandle);
            
See also
Prev | Next