Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a Text File in Julia

I have a string

a = """
---
title: Just a test
author: Me
date: 2022-01-03
---

# Test Header 
Some text.
"""

from which I want to create a file foobar.jmd. What is the best way of doing this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

fname = "foobar.jmd"
dirpath = "/tmp"
fpath = joinpath(dirpath, fname)

open(fpath, "w") do file
    write(file, a)
end

More examples e.g. here https://en.wikibooks.org/wiki/Introducing_Julia/Working_with_text_files

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading