Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read duplicate string in a text file in vb.net
    primarykey
    data
    text
    <p>I want this program to open a text file and find those specific character and add the words after that into the list (each character has specific subitem in the list). It work well if there is no duplication. But if I have list like:</p> <pre><code> /* First row of the list */ #Alireza %Human &amp;1 @$1200 $*1 *$1000 /* ' Second row */ #Behzad %Human &amp;1 @$1340 $*1 *$1000 /* ' And third row */ #Samaneh %Human &amp;1 @$1570 $*1 *$1230 </code></pre> <p>then it only add the first row. I also make a while loop but it will only add first row to other rows. Is there anyone can help please!(by the way my list include 6 columns )</p> <p>this is the code:</p> <pre><code> Public code As String Public cat As String Public stock As Integer Public price As Double Public sold As Double Public cost As Double Public i As Integer Public Sub _Load(ByVal FileName As String) Dim strLines() As String Dim strLine As String Dim strData As String Dim objFileInfo As New FileInfo(FileName) strData = My.Computer.FileSystem.ReadAllText(FileName) strLines = strData.Split(New String() {ControlChars.CrLf}, StringSplitOptions.RemoveEmptyEntries) For Each strLine In strLines If strLine.StartsWith("#") Then code = strLine.Substring(1) End If strLine = Nothing Next For Each strLine In strLines If strLine.StartsWith("%") Then cat = strLine.Substring(1) Exit For End If strLine = Nothing Next For Each strLine In strLines If strLine.StartsWith("&amp;") Then stock = strLine.Substring(1) Exit For End If strLine = Nothing Next For Each strLine In strLines If strLine.StartsWith("@$") Then price = strLine.Substring(2) Exit For End If strLine = Nothing Next For Each strLine In strLines If strLine.StartsWith("$*") Then sold = strLine.Substring(2) Exit For End If strLine = Nothing Next For Each strLine In strLines If strLine.StartsWith("*$") Then cost = strLine.Substring(2) Exit For End If strLine = Nothing Next End Sub Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolImport.Click Dim ans As String OpenFileDialog1.Title = "What are you looking for?" OpenFileDialog1.InitialDirectory = Application.StartupPath OpenFileDialog1.Filter = "text Files (*.txt)|*.txt|Data Files (*.dat)|*.dat|All files (*.*)|*.*" OpenFileDialog1.FileName = "myList" Try If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Dim sr As StreamReader = New StreamReader(OpenFileDialog1.FileName) Do While sr.Peek &gt; -1 _Load(OpenFileDialog1.FileName) Dim list As New ListViewItem(code) list.SubItems.Add(cat) list.SubItems.Add(stock) list.SubItems.Add(price) list.SubItems.Add(sold) list.SubItems.Add(cost) listClothes.Items.Add(list) i += 1 MessageBox.Show("Your list has been uploaded successfully", "ccc!", MessageBoxButtons.OK, MessageBoxIcon.Information) Loop End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload