Vb.net Read Text from file -


i have text, text file it's name lucky.ini

[group1]
number = 0811
coupon = 0118
[group2]
number = 4852
coupon = 7112

how read text textbox, want read number after "=" , i've 2 groups. first, cheap , second, rich
enter image description here

i used regex parse text file. see code below

imports system.io  imports system.text.regularexpressions  imports system.data  public class form1      const filename string = "c:\temp\test.txt"        '[group1]      'number = 0811      'coupon = 0118      '[group2]      'number = 4852      'coupon = 7112      sub new()            ' call required designer.          initializecomponent()            ' add initialization after initializecomponent() call.          dim dt new datatable          dt.columns.add("group", gettype(string))          dt.columns.add("number", gettype(string))          dt.columns.add("coupon", gettype(string))            dim input string = file.readalltext(filename)          dim pattern string = "[^\[]*\[(?'name'[^\]]+)\]\s*number\s+=\s*(?'number'\d+)\s*coupon\s*=\s*(?'coupon'\d+)"          dim expr new regex(pattern, regexoptions.singleline)            dim matches matchcollection = expr.matches(input)          each m match in matches              dim name string = m.groups("name").value              dim number string = m.groups("number").value              dim coupon string = m.groups("coupon").value              dt.rows.add(new string() {name, number, coupon})          next m            datagridview1.datasource = dt            dim richnumber = dt.rows(0)("number")          dim richcoupon = dt.rows(0)("coupon")            dim cheapnumber = dt.rows(1)("number")          dim cheapcoupon = dt.rows(1)("coupon")        end sub    end class  ​


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -