Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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

Posted

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))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...