Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

identifying tab deliminated 2

Status
Not open for further replies.

G00GLER

Instructor
May 17, 2005
57
US

I guess what i am trying to figure out is how to capture items that fall between tab marks

I'm trying to capture in a text file what is in between tabs, apparently " " doesn't cut it any suggestions?

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim YourString As String = "Just some text (1/1/2005 ) be   tween (not a date here)     dates.(2/4/2005) End of text."

        Dim b As ArrayList = GetValsFromText(YourString, "   ", "   ")
        For Each item As String In b
            Response.Write(item)
            Response.Write("<br>")
        Next
    End Sub


    Public Function GetValsFromText(ByVal sText As String, ByVal char1 As String, ByVal char2 As String) As ArrayList
        Dim lst As New ArrayList
        Dim arr1() As String = sText.Split(char2)
        For Each sItem As String In arr1
            Dim arr2() As String = sItem.Split(char1)
            If arr2.Length >= 2 Then
                lst.Add(arr2(arr2.Length - 1))
            End If
        Next
        Return lst
    End Function
 
This would be difficult with ASP.NET. IF you are using SQL server, I would use a DTS package to do it.
 
unfortunately I am not I just have a long tab deliminated text file that I am trying to convert into XML

but your hypothetical suggestion has given me an idea, maybe i need to load this into an access or sqlserver table to get this particular job done
 
Have you tried chr(9) or whatever the ascii code to character function is? This sounds like pretty simple parsing, absolutely within the realm of .NET.

________________________________________
Andrew
 
The example above only works when the first delimiter is different than the second one. Since your first and second delimiters are both the same then you will need to use this.

Assumig you are proccessing an entire tab delimited file with carriage returns, if not, then the you don't need to use the first arr1.

YourString=replace(YourString,chr(10),"")
dim lst as new ArrayList
dim arr1() as string=YourString.split(chr(13))
for each sLine as string in arr1
dim arr2() as string=sLine.split(chr(9))
for each sTab as string in arr2
lst.add(sTab)
next
next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top