473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

remove blank strings in arraylist

below is some codes.

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 ?

****************************

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

****************************


Jan 19 '06 #1
2 6480

"James" <jk****@hotmail.com> wrote in message
news:es**************@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 ?
So you're trying to leave out blank lines and comments?
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.
Jan 19 '06 #2
"James" <jk****@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/>

Jan 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: steve smith | last post by:
Hi I'm still having some problems getting my head round this language. A couple of things don't seem to work for me. First I am trying to obtan a count of the number of words in a sting, so am...
7
by: Franck Diastein | last post by:
Hi, I'm trying to remove items from a collection this way: foreach(Object myO in ObjectCol){ if(myO != "xxx"){ myO.Remove(); } } But I'm having an error telling me that Collection was...
3
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method...
3
by: Ryan Liu | last post by:
Hi, What does ArrayList.Synchronized really do for an ArrayList? Is that equal to add lock(this) for all its public methods and properties? Not just for Add()/Insert()/Remvoe()/Count, but also...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
2
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the...
10
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a...
10
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I wanted to go through each entry(?) of ArrayList and remove some particular entry. So I tried following but it throws exception at runtime: foreach (myEntry entry in myArrayList) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.