Closed prakashboston closed 10 months ago
Hello @prakashboston, add a function as described in a documentation
It could be like this:
public class MyFunction : IFunction
{
public string Name { get; } = "Format";
public bool CanHandleNullArguments { get; }
public InternalEvaluatorValue Execute(List<InternalEvaluatorValue> args, ValueFactory factory)
{
var format = args[0].Word;
var formatArguments = args.Skip(1).Cast<object>().ToArray();
var result = string.Format(format, formatArguments);
return factory.Word.Create(result);
}
}
class Program
{
static void Main()
{
var sss = string.Format("{0} hello {0}, {1}", 8, "hey");
var ns = CreateNoString();
var res = ns.CalcWord("Format('{0} hello {0}, {1}', 8, 'hey')");
}
static NoStringEvaluator CreateNoString()
{
static void Configure(NoStringEvaluatorOptions opt)
{
opt.WithFunctionsFrom(typeof(Program))
}
return NoStringEvaluator.CreateFacade(Configure).Evaluator;
}
}
Thank you so much for your response.Its working fine and good to use this library
But keep in mind this snippet is not optimized, if you need a performance improvement change the row var formatArguments = args.Skip(1).Cast<object>().ToArray();
String.Format() manages formatting including the position, alignment, and format type