SlideShare una empresa de Scribd logo
1 de 12
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
A CSV file opened in Excel
The data one, two, three, four and five would be separated
                by commas in a CSV file
Using VB to read in a CSV file
Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")

Console.WriteLine(fileReader)

Console.ReadLine()                              Notice the
                                              extension CSV
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .




     HOW AM I
  GONNA SPILT UP
   THAT CSV FILE!
Splitting up CSV’s by Comma
Ideally we want to spilt the CSV file up where the comma
                           exists

                                     Splitting the file
                                       every time a
                                     comma is found
Splitting up CSV’s by Comma
 We can use the split() function to split the CSV by commas




Split(aString, ",")
 The name of the                    Where we want the
string variable we                    split to occur
 want to split up
Splitting up CSV’s by Comma
We need something which is going to be able to hold these
                   separate values
Splitting up CSV’s by Comma
Dim s As String

Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText("example.csv")


s = fileReader
Dim fields As Array                    An Array will hold
                                        the split up CSV
fields = Split(s, ",")
Splitting up CSV’s by Comma
Dim s As String

Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")

s = fileReader
Dim fields As Array

fields = 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
Splitting up CSV’s by Comma
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .




         PHEW!

Más contenido relacionado

Similar a Splitting up text

1.CSV stands for commma seperated values which are applied to move.pdf
1.CSV stands for commma seperated values which are applied to move.pdf1.CSV stands for commma seperated values which are applied to move.pdf
1.CSV stands for commma seperated values which are applied to move.pdf
anilart346
 
COMELEC III - Bash unit 1
COMELEC III - Bash unit 1COMELEC III - Bash unit 1
COMELEC III - Bash unit 1
Binsent Ribera
 

Similar a Splitting up text (20)

CSV File Manipulation
CSV File ManipulationCSV File Manipulation
CSV File Manipulation
 
Data file handling in python binary & csv files
Data file handling in python binary & csv filesData file handling in python binary & csv files
Data file handling in python binary & csv files
 
Data file handling in python binary & csv files
Data file handling in python binary & csv filesData file handling in python binary & csv files
Data file handling in python binary & csv files
 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV Connectivity
 
Csv file read and write
Csv file read and writeCsv file read and write
Csv file read and write
 
1.CSV stands for commma seperated values which are applied to move.pdf
1.CSV stands for commma seperated values which are applied to move.pdf1.CSV stands for commma seperated values which are applied to move.pdf
1.CSV stands for commma seperated values which are applied to move.pdf
 
CSV_FILES.pptx
CSV_FILES.pptxCSV_FILES.pptx
CSV_FILES.pptx
 
oops (1).pptx
oops (1).pptxoops (1).pptx
oops (1).pptx
 
Hbase
HbaseHbase
Hbase
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and Security
 
CSV import in AtoM
CSV import in AtoMCSV import in AtoM
CSV import in AtoM
 
An introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel AvivAn introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
 
Learning Cassandra NoSQL
Learning Cassandra NoSQLLearning Cassandra NoSQL
Learning Cassandra NoSQL
 
Csv python-project
Csv python-projectCsv python-project
Csv python-project
 
Dealing with files in python specially CSV files
Dealing with files in python specially CSV filesDealing with files in python specially CSV files
Dealing with files in python specially CSV files
 
COMELEC III - Bash unit 1
COMELEC III - Bash unit 1COMELEC III - Bash unit 1
COMELEC III - Bash unit 1
 
Machine learning session 3
Machine learning session 3Machine learning session 3
Machine learning session 3
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 

Más de Peter Andrews (12)

Trimming text
Trimming textTrimming text
Trimming text
 
Reading in files
Reading in filesReading in files
Reading in files
 
Is numeric
Is numericIs numeric
Is numeric
 
Arrays
ArraysArrays
Arrays
 
Loops
LoopsLoops
Loops
 
Rounding numbers
Rounding numbersRounding numbers
Rounding numbers
 
Select case
Select caseSelect case
Select case
 
If
IfIf
If
 
Collecting user input
Collecting user inputCollecting user input
Collecting user input
 
Variables
VariablesVariables
Variables
 
Hello world
Hello worldHello world
Hello world
 
Flow charts
Flow chartsFlow charts
Flow charts
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Splitting up text

  • 1.
  • 2. 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
  • 3. A CSV file opened in Excel The data one, two, three, four and five would be separated by commas in a CSV file
  • 4. Using VB to read in a CSV file Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv") Console.WriteLine(fileReader) Console.ReadLine() Notice the extension CSV
  • 5. MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . . HOW AM I GONNA SPILT UP THAT CSV FILE!
  • 6. Splitting up CSV’s by Comma Ideally we want to spilt the CSV file up where the comma exists Splitting the file every time a comma is found
  • 7. Splitting up CSV’s by Comma We can use the split() function to split the CSV by commas Split(aString, ",") The name of the Where we want the string variable we split to occur want to split up
  • 8. Splitting up CSV’s by Comma We need something which is going to be able to hold these separate values
  • 9. Splitting up CSV’s by Comma Dim s As String Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText("example.csv") s = fileReader Dim fields As Array An Array will hold the split up CSV fields = Split(s, ",")
  • 10. Splitting up CSV’s by Comma Dim s As String Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv") s = fileReader Dim fields As Array fields = 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
  • 12. MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . . PHEW!