|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
remove blank strings in arraylistmy arraylist below reads from a file. My files contains blank line (ie carriage return) My message dialog shows all strings being captured. However i do not want my array to contain "blank" string/line/carriage return How do i remove the index so that my arraylist become smaller ? **************************** Dim sr As StreamReader = New StreamReader(filespath) Dim line As String Do line = sr.ReadLine 'add each line into arraylist If InStr(line, ";") <> 1 Then filestoexecute.Add(line) End If Loop Until line Is Nothing sr.Close() ***************************** For Each i In filestoexecute MessageBox.Show(i) Next **************************** "James" <jkk***@hotmail.com> wrote in message So you're trying to leave out blank lines and comments?news:eszU6GNHGHA.1628@TK2MSFTNGP12.phx.gbl... > my arraylist below reads from a file. My files contains blank line (ie > carriage return) .. . . > How do i remove the index so that my arraylist become smaller ? > If InStr(line, ";") <> 1 Then If the line is blank, Instr() will return 0, which isn't 1, so will add the line. To exclude blank lines as well (if I can remember the "old" syntax for this), try this : If Len( line ) > 0 _ AndAlso Instr( line, ";" ) <> 1 _ Then (BTW, using the methods on the String class, thios would be) If line.Length > 0 _ AndAlso Not line.StartsWith( ";" ) _ Then HTH, Phill W.
Show quote
Hide quote
"James" <jkk***@hotmail.com> schrieb: \\\> my arraylist below reads from a file. My files contains blank line (ie > carriage return) > > My message dialog shows all strings being captured. However i do not want > my array to contain "blank" string/line/carriage return > > How do i remove the index so that my arraylist become smaller ? >[...] > Do > > line = sr.ReadLine > > 'add each line into arraylist > > If InStr(line, ";") <> 1 Then If Len(line) > 0 AndAlso InStr(line, ";") <> 1 Then ... End If /// If you want to check the string with spaces on the right and left end of the string, use 'Len(Trim(line)) > 0'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Insert data in VB.Net
Copying one project to another create user and add to admin group under local system Run code under diffrent user Can I do this on One line of code? How to insert a page break in multi-page document? Trick to getting System.Web.Mail to work? windows xp cd writing support (can't find imapi.h) HELP! Tray icon to change IP Gateway? Farsi Font |
|||||||||||||||||||||||