rahul_0716 Posted May 9, 2009 Posted May 9, 2009 hai guys i have a text file with the content as Number:1234567890 Alphabet:ldskfjlds Alphabet:weiouruewoiru Alphabet:abcdefghijklmnopqrstuvwxyz Alphabet:abcdefghijklmnopqrstuvwxyz Number:1234567890 so while reading the file if encounter string "Number:" then i have to read the number eg:124567890 and insert into the database. i was able to identify the presence of the string in the text file by the code if (System.Text.RegularExpressions.Regex.IsMatch(st,"Number:") Textbox1.Text="found"; i think i may be possible with System.Text Namespace Methods..but i dont know thosemethods Quote
JumpyNET Posted May 9, 2009 Posted May 9, 2009 You might want to look into Like and Split. Here's something to get you started: Dim TestText As String = _ "Number:1234567890 Alphabet:ldskfjlds Alphabet:weiouruewoiru" & vbCrLf & _ "Alphabet:abcdefghijklmnopqrstuvwxyz" & vbCrLf & _ "Alphabet:abcdefghijklmnopqrstuvwxyz" & vbCrLf & _ "Number:1234567890" Dim Rows() As String = Split(TestText, vbCrLf) For Each OneRow As String In Rows Dim Items() As String = Split(OneRow, " ") For Each OneItem As String In Items If OneItem Like "Number:*" Then Debug.Print(Split(OneItem, "Number:")(1)) ElseIf OneItem Like "Alphabet:*" Then Debug.Print(Split(OneItem, "Alphabet:")(1)) End If Next Next And then there's ofcourse: Debug.Print(Microsoft.VisualBasic.Left("ABCDEFG", 3)) Debug.Print(Microsoft.VisualBasic.Right("ABCDEFG", 3)) Debug.Print(Microsoft.VisualBasic.Mid("ABCDEFG", 3, 3)) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.