Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse from a string rather than a file #43

Open
yetipicard opened this issue Apr 3, 2024 · 1 comment
Open

Parse from a string rather than a file #43

yetipicard opened this issue Apr 3, 2024 · 1 comment

Comments

@yetipicard
Copy link

Hi,

I need to parse a string representing a toml file. Tommy seems to only be able to read from a file from what I've seen. Is this right, or did I miss something?

@dezhidki
Copy link
Owner

dezhidki commented Apr 3, 2024

Hi!

Sure, you can pass a StringReader to Tommy containing the TOML string as such:

var tomlString = """
title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
""";

var table= TOML.Parse(new StringReader(tomlString));

Such an approach is used, for example, in the unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants