Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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.

  • *Gurus*
Posted

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

Posted

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?

Posted
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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...