To extract a string until it encounters a space after a specifies string from textf

rahul_0716

Newcomer
Joined
May 8, 2009
Messages
2
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
 
You might want to look into Like and Split. Here's something to get you started:
Code:
        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:
Code:
        Debug.Print(Microsoft.VisualBasic.Left("ABCDEFG", 3))
        Debug.Print(Microsoft.VisualBasic.Right("ABCDEFG", 3))
        Debug.Print(Microsoft.VisualBasic.Mid("ABCDEFG", 3, 3))
 
Back
Top