c# - Look for words in a textbox text and display in data grid -
i need program windows form in c#, needs textbox , button. in textbox have type programming instruction example: for(i=0;i<10;i++)
then click button , in datagrid should displayed this:
- for - cycle
- ( - agrupation
- i - variable
= - asignation
and on
how can identify parts of text?
i've tried foreach char i'm messed :( please
here solution can use cobbled together. highly recommend familiarise regular expressions:
https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx
and here nice tester used: http://regexstorm.net/tester
using system.text.regularexpressions; string input = "for(i=0;i<10;i++)"; string pattern = @"^(\w+)(\w)(\w)(\w).*$"; matchcollection matches = regex.matches(input, pattern); string cycle = matches[0].groups[1].value; string agrupation = matches[0].groups[2].value; string variable = matches[0].groups[3].value; string asignation = matches[0].groups[4].value; string test = string.format("cycle: {0}, agrupation: {1}, variable={2}, asignation: {3}", cycle, agrupation, variable, asignation); console.writeline(test);
Comments
Post a Comment