Home
News
Products
     uCalc Fast Math Parser
     uCalc Language Builder
     Windows Calculator
     DOS Calculator
Downloads
Message Forums
Satisfaction Survey
FAQ
Contact
Privacy Statement
Testimonials
Purchase

Strings
 

This sample demonstrates how strings can be used.  The user-defined Len function returns the length (in number of characters) of the given string.  In addition to returning numeric values, the parser can return string values as well, using ucEvalStr.  The user-defined Left function returns a string. With these user-defined functions, string expressions such as the following can be evaluated:

Left('Hello there', 5) + ' World'
Left(MyString, 5) & ' World'
Len(MyString) - Len('Hello')

(note:  MyString is a  user-defined string variable)

Visual Basic

Private Sub Form_Load()
   ucDefineFunction "Len(text$)", AddressOf ucalcLen
   ucDefineFunction "Left$(text$,length)", _
      AddressOf ucalcLeft
   ucDefineVariable "MyString = 'This is my string' "
End Sub

Private Sub Command1_Click()
   Expression$ = InputBox("Enter an expression")
   MsgBox ucEvalStr(Expression$)
End Sub

Function ucalcLen() As Double
    ucalcLen = Len(ucParamStr(1))
End Function

Function ucalcLeft() As Double
   ucParamStr(0) = Left$(ucParamStr(1), ucParam(2))
End Function

VC++ or C++ Builder

#include <iostream>
#include "ucalc.cpp"

using namespace std;

long double ucalcLen();
long double ucalcLeft();

int main()
{
  char Expression[80];

  ucDefineFunction("Len(text$)",
                   reinterpret_cast<long>(ucalcLen));
  ucDefineFunction("Left$(text$,length)",
                   reinterpret_cast<long>(ucalcLeft));
  ucDefineVariable("MyString = 'This is my string' ");

  while(1)
  {
    cout << "Enter an expression:  " << endl;
    cin.getline(Expression, 80, '\n');
    cout << "Answer:  " << ucEvalStr(Expression)
         << endl;
  }

  return 0;
}

long double ucalcLen()
{
  return strlen(ucParamStr(1));
}

long double ucalcLeft()
{
  char StringValue[80];
  long StringLength;

  strcpy(StringValue, ucGetParamStr(1));
  StringLength = ucParam[2];
  StringValue[StringLength] = '\0';
  ucSetParamStr(0, StringValue);

  return 0;
}

Delphi

procedure TForm1.FormCreate(Sender: TObject);
begin
  ucDefineFunction('Len(text$)',
                   Longword( @ucalcLength ));
  ucDefineFunction('Left$(text$,length)',
                   Longword( @ucalcLeft ));
  ucDefineVariable('MyString = "This is my string" ');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Expression: string;
begin
  Expression := InputBox('', 'Enter an expression:',
                'Left("Hello there", 6) + "World"');
  Edit1.Text := ucEvalStr(Expression) );
end;

function ucalcLength: Extended;
begin
    ucalcLength := Length(ucParamStr(1));
end;

function ucalcLeft: Extended;
begin
  ucSetParamStr(0, copy(ucParamStr(1), 1,
     Trunc(ucParam[2])));
end;

 


 

Download fastmath.zip (~145K)






|Home| |News| |Products| | uCalc Fast Math Parser| | uCalc Language Builder| | Windows Calculator| | DOS Calculator| |Downloads| |Message Forums| |Satisfaction Survey| |FAQ| |Contact| |Privacy Statement| |Testimonials| |Purchase|


Copyright © 2006 by Daniel Corbier