Reading in other files•   VB can read in more than just text files•   You can also read in CSV files•   Comma Separated Va...
A CSV file opened in ExcelThe data one, two, three, four and five would be separated                by commas in a CSV file
Using VB to read in a CSV fileDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")Con...
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .     HOW AM I  GONNA SPILT UP   THAT CSV FILE!
Splitting up CSV’s by CommaIdeally we want to spilt the CSV file up where the comma                           exists      ...
Splitting up CSV’s by Comma We can use the split() function to split the CSV by commasSplit(aString, ",") The name of the ...
Splitting up CSV’s by CommaWe need something which is going to be able to hold these                   separate values
Splitting up CSV’s by CommaDim s As StringDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText("example...
Splitting up CSV’s by CommaDim s As StringDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText(" Y:exam...
Splitting up CSV’s by Comma
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .         PHEW!
Splitting up text
Upcoming SlideShare
Loading in...5
×

Splitting up text

188

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
188
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Splitting up text

  1. 1. Reading in other files• VB can read in more than just text files• You can also read in CSV files• Comma Separated Value files• CSV is a way of storing data separated by commas
  2. 2. A CSV file opened in ExcelThe data one, two, three, four and five would be separated by commas in a CSV file
  3. 3. Using VB to read in a CSV fileDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")Console.WriteLine(fileReader)Console.ReadLine() Notice the extension CSV
  4. 4. MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . . HOW AM I GONNA SPILT UP THAT CSV FILE!
  5. 5. Splitting up CSV’s by CommaIdeally we want to spilt the CSV file up where the comma exists Splitting the file every time a comma is found
  6. 6. Splitting up CSV’s by Comma We can use the split() function to split the CSV by commasSplit(aString, ",") The name of the Where we want thestring variable we split to occur want to split up
  7. 7. Splitting up CSV’s by CommaWe need something which is going to be able to hold these separate values
  8. 8. Splitting up CSV’s by CommaDim s As StringDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText("example.csv")s = fileReaderDim fields As Array An Array will hold the split up CSVfields = Split(s, ",")
  9. 9. Splitting up CSV’s by CommaDim s As StringDim fileReader As StringfileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")s = fileReaderDim fields As Arrayfields = Split(s, ",")For i = 0 To UBound(fields)Console.WriteLine("word " & i & " " & fields(i))Console.WriteLine("*****************************************")Next Using a for loop to write the contents of the array
  10. 10. Splitting up CSV’s by Comma
  11. 11. MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . . PHEW!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×