Guest Danno Posted November 9, 2002 Posted November 9, 2002 I understand how to access a file with the StreamReader, but only with 'ReadLine()'. How do I seperate that line into the three separate sections that are seperated by commas? Quote
*Experts* Bucky Posted November 9, 2002 *Experts* Posted November 9, 2002 You could use the Split method of the string to split it into an array. Dim sToSplit As String ' String to split up Dim sParts() As String ' Comma-separated parts of the string ' Get sToSplit here by reading a line from the stream sParts = sToSplit.Split(",") The array item sParts(0) will be the first part, sParts(1) the second, and sParts(2) the third. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Guest Danno Posted November 9, 2002 Posted November 9, 2002 Ok, great answer...but... I get the following error with Option Strict on "Option Strict On disallows implicit conversions from 'String' to 'Char'" Here is my code (error area in bold): Dim name(), tempString As String tempString = objSR.ReadLine name = tempString.Split(",") lstDetails.Items.Add(name) Any suggestions? I tried to cast one way or the other with CChar but it hasn't worked. Quote
*Gurus* Derek Stone Posted November 9, 2002 *Gurus* Posted November 9, 2002 Try the following. Dim strName() As String, tempString As String, i As Integer tempString = "Testing,out,explicit,type,casting" strName = tempString.Split(","c) For i = strName.GetLowerBound(0) To strName.GetUpperBound(0) lstDetails.Items.Add(strName(i)) Next Quote Posting Guidelines
Guest Danno Posted November 9, 2002 Posted November 9, 2002 That give each item (thanks!) but I need to put each item into another array (three sections into 3 different arrays.....this is very confusing! I need to break it up so that: array1 = substring1 array2 = substring 2 array3 = substring 3 and do it in a loop (some way to modify your for/next loop? Quote
Guest Danno Posted November 9, 2002 Posted November 9, 2002 And what is the easiest way to strip off the double quotes with Option Strict is on? The file has the first set of data in double quotes and if I try to Trim it is says it can't handle the double quote char within a string! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.