The Cobra Programming Language
How To
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Pass References To Methods
Translate Pseudo Code To Cobra1
Translate Pseudo Code To Cobra2
Implement IEnumerable1
Implement IEnumerable2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
GTK
Access MySQL
""" Reading files in Cobra relies on the libraries and therefore is pretty the much the same as C# or VB. See the BCL (Base Class Library) docs for File, StreamReader, StreamWriter, TextReader and TextWriter for more. """ class Test def main is shared nl = Environment.newLine fileName = 'test-file.text' # write a whole file File.writeAllText(fileName, 'This is a test file.[nl]To make sure there is a file to work with.[nl]') # read a whole file contents = File.readAllText(fileName) assert 'test' in contents # The `in` operator works for strings: <substring> in <string> ==> bool # read line by line num = 1 using sr = File.openText(fileName) while true line = sr.readLine if line is nil break print '[num]. len=[line.length] "[line.trim]"' num += 1 # be nice about IO errors fileName = 'bad-file-name.text' try contents = File.readAllText(fileName) catch ioe as IOException print 'I/O Error: [ioe.message]' success assert 'test' in contents