C#C
C#3y ago
malkav

✅ My stringbuilder is skipping lines

Aside from a previous post I made: ✅ Familiarity with `YamlDotNet` package, parsing to strongly typed object keeps failing

I am trying to parse some strings lines, but the stringbuilder itself is already skipping lines and I'm not entirely sure why it skips those lines.

The builder part (see the stream variable later):
StringBuilder builder = new();
using StreamReader reader = new(stream);
await reader.ReadLineAsync();

while (await reader.ReadLineAsync() is { } line && line != "---")
{
  builder.AppendLine(await reader.ReadLineAsync());
}


The stream variable:
---
title: FP Config
hero_settings:
  title: my title
  subtitle: test meuk
  button_text: mail
client_header:
  title: clients
  subtitle: of us
clients: []
services_header:
  title: services
  subtitle: services
expertise_header:
  title: expertise
  subtitle: stuff
about_header:
  title: about
  subtitle: about
about:
  - leadmct: true
    mct: true
    mvp: true
    title: bryce
    subtitle: manager
    image: url.to/image/path.png
partnerships_header:
  title: partnerships
  subtitle: partners
---


And what I get in the console is the following:
hero_settings:
   subtitle: test meuk
client_header:
   subtitle: of us
services_header:
   subtitle: services
   title: expertise
about_header:
   subtitle: about
   - leadmct: true
     mvp: true
     subtitle: manager
partnerships_header:
   subtitle: partners


So my stringbuilder already fails 😅
I get more when I just do reader.ReadToEnd().Replace("---", "").Trim() but that will skip the body which could come after the last "---" part.
So I need a way to include the body as well
Was this page helpful?