-4

I am writing a backend API that generates a structured textfile. Based off user input certain strings are filled via interpolation

// actual string literal
string message = $@"Version {version} of Markdown Monster is now available.

Released on: {releaseDate:MMM dd, yyyy} 
{newStuff}
";

https://weblog.west-wind.com/posts/2016/Dec/27/Back-to-Basics-String-Interpolation-in-C.

I have this creating a 100 LOC text file filling in needed with JSON values I'm passed.

Sometimes only "sections" of the text file will be needed. How can I tokenize and assign a value to a section of the text to be generated if needed? There are a lot of possible permutations, around 30 different text files to be generated by the template.

So imagine an XML file and break it up in your head into 30 separate pieces. Programmatically put some number of pieces in some order via arbitrary user input.

//piece A
<?xml version = "1.0" encoding = "utf-8"?>

<!-- planes.xsd
 A simple schema for planes.xml
 -->
//piece b
<xsd:element name = "planes">
    <xsd:complexType>
        <xsd:all>
            <xsd:element name = "make"
                         type = "xsd:string"
                         minOccurs = "1" 
                         maxOccurs = "unbounded" />
        </xsd:all>
    </xsd:complexType>
 </xsd:element>
</xsd:schema>

//piece C
lorem ipsosume....

Formatting and indention must also be preserved.

  • 1
    I don't understand wha you mean by "sections", "tokenize" etc. Could you please give examples? – Klaus Gütter Nov 17 '18 at 14:40
  • Put some of the text in a block ` 1977 Cessna Skyhawk Light blue and white ` Iff the user triggers the flag that text appears on the deliverable. The above code is "block A" so if I had thirty flags or so ""block A" may appear but sometimes "block B" or "C" in some order will appear. Hope that clears it up.@klausGutter – user5541158 Nov 17 '18 at 15:47
  • Sorry, it does not get any clearer for me – Klaus Gütter Nov 17 '18 at 15:55
  • @KlausGütter edited OP hopefully clears it up – user5541158 Nov 17 '18 at 16:03

1 Answers1

0

You could use razor - it’s a text templating engine designed to do this sort of thing. This question (and answers) has information on using it: Using Razor outside of MVC in .NET Core

RQDQ
  • 15,461
  • 2
  • 32
  • 59