You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can do it yourself in your own code!
BasicSharp allows to define functions that can be used within basic scripts.
Example for contains:
usingSystem;usingBasicSharp;namespaceMyApp{classProgram{publicstaticValueContains(Interpreterinterpreter,List<Value>args){if(args.Count<2)// We expect 2 argumentthrownewArgumentException();stringa=args[0].Convert(ValueType.String).String;// convert argument to make sure it is stringstringb=args[1].Convert(ValueType.String).String;returnValue(a.contains(b)?1.0:0.0);// convert true/false into 1 or 0}staticvoidMain(string[]args){stringcode="print contains(\"hello world\", \"world\" )";Interpreterbasic=newInterpreter(code);// add our 'contains' function to basic interpreter basic.AddFunction('contains',Contains);basic.printHandler+=Console.WriteLine;basic.inputHandler+=Console.ReadLine;try{basic.Exec();}catch(BasicExceptione){Console.WriteLine(e.Message);Console.WriteLine(e.Line);}}}}
Above code was written from memory without trying to compile it.
Hi i want to say this is great piece of work.
Can you please add
*contains
*indexOf
*startWith
string methods pls ?
I would love to use it for simple calculations and string modifications...
The text was updated successfully, but these errors were encountered: