Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Monday, March 26, 2012

StringCollection

Hi

I got this function in C#:


internal string JoinStringCollection(StringCollection SC)
{
string[] ToListArray = new string[SC.Count];
SC.CopyTo(ToListArray,0);
return string.Join("; ",ToListArray);
}

I converted it as follows, but cant seem to get the right syntax:


Friend Function JoinStringCollection(ByVal SC As StringCollection) As String

Dim ToListArray() As String = New String(SC.Count) 'This generates error, expects char?
SC.CopyTo(ToListArray, 0)
Return String.Join("; ", ToListArray)
End Function

Add "{}" at the end of the "New" statement

AutoFed
Try this:
Dim ToListArray(SC.Count) As String

Tuesday, March 13, 2012

stuck in a loop

Hi

I try to use this piece of code, but the page seems to get stuck in the loop. What am I doing wrong here?

Function NumberOfLinesInFile()
Dim path As String = Server.MapPath("row.txt")
Dim sr As StreamReader = New StreamReader(path)
Dim i As Integer
i = 0
Do While sr.Peek() >= 0
i = i + 1
Loop
sr.Close()
Return i
End Function

Regards

Mhello, what if sr.Peek() is always >= 0 ? check the values returned by sr !!!
The Peek function does not move to the next character, it only consumes it. Try using the sr.Read() instead.

hope this helps,

sivilian