Here's a quick example of how to start doing this with regular expressions. This won't be bulletproof against anything you throw at it, but it should make for a good start.
Be sure to add : Imports System.Text.RegularExpressions to your .vb file
'This string is an example input. It demonstrates that the method below 'will find the sum "2345+ 3256236" but will skip over things like ' if + .04g ' 1.23 + 4 ' etc... Dim input As String = _ "aoe%rdes 2345+ 3256236 if + .04g rcfo 8 3 . 1.23 + 4 the#r whuts" Dim pattern As String = "\s\d+\s*\+\s*\d+(?=\s|$)" For Each _match As Match In Regex.Matches(input, pattern) Dim a = _match.Value.Split("+"c) 'Match extracts "2345+ 3256325" Dim x As Integer Dim y As Integer If Integer.TryParse(a(0), x) AndAlso Integer.TryParse(a(1), y) Then Console.WriteLine("Found the Sum : " & x & " + " & y) Console.WriteLine("Sum is : " & x + y) Else Console.WriteLine("Match failed to parse") End If Next
The regular expression can be broken down as
\s '(definitely) one whitespace \d+ 'followed by any number of integer digits \s* 'followed by (possibly) a whitespace \+ 'followed by (definitely) a "+" \s* 'followed by (possibly) a whitespace \d+ 'followed by any number of integer digits (?=\s|$) 'followed by (definitely) either a whitespace or EOL
Read more here :
Regular Expression Language - Quick Reference
.NET Framework Regular Expressions
Regular Expressions Reference
what is 20 + 26orI have 20 apples and 26 fingersorwhatever you do, don't tell me the sum of 20 + 26, orWhat are 26.9+7 things % 133t k0derz can d0?textbox- like no alphabets allowed. that will simplify your homework :) also, what kind of a person will type "what's 20+20" rather than "20+20"clicks button