Reputation: 31
I cannot find a way to express a string. So for example if I type the string " ""Hello "" & 10*20/(21/2) & "" World"" "
In a Textbox
control or Console.ReadLine()
input it should return Hello 19,0476190476191 World
. Can I do this?
Upvotes: 0
Views: 86
Reputation: 172270
If you use single quotes and +
as the string concatenation character, you can abuse the expression evaluation engine of ADO.NET:
Dim expression As String = " 'Hello ' + 10*20/(21/2) + ' World' "
Dim result = New DataTable().Compute(expression, Nothing)
' Prints: Hello 19.047619047619 World
Console.WriteLine(result)
The DataColumn.Expression
MSDN page has a list of all supported operators.
(On the other hand, writing a simple Basic expression parser is always a fun exercise, so don't let that stop you.)
Upvotes: 2