Flowinator
Flowinator

Reputation: 13

Stringbuilder AppendLine is adding one new line too much

I am trying to generate a QR Code with C# in Visual Studio... For each Big Tag I created a class with the childTags... I override the ToString() function to use Stringbuilder and add each tag to it

class QRCdtrInf
{
    public string IBAN;
    public QRCdtr Cdtr;
    public override string ToString()
    {
        var sb = new StringBuilder();
        sb.AppendLine(IBAN);
        sb.Append(Cdtr.ToString());
        return sb.ToString();
    }
}

at the end there is a class QRData which takes all the Classes ToString and append it..

class QRData
{
    public QRHeader Header;
    public QRCdtrInf CdtrInf;
    public QRUltmtCdtr UltmtCdtr;
    public QRCcyAmt CcyAmt;
    public QRUltmtDbtr UltmtDbtr;
    public QRRmtInf RmtInf;
    public QRAltPmtInf AltPmtInf;

    public override string ToString()
    {
        var sb = new StringBuilder();
        sb.Append(Header.ToString());
        sb.Append(CdtrInf.ToString());
        sb.Append(UltmtCdtr.ToString());
        sb.Append(CcyAmt.ToString());
        sb.Append(UltmtDbtr.ToString());
        sb.Append(RmtInf.ToString());
        return sb.ToString();
    }

}

I then Send it to Encoding and when I scan it, I always get one line too much for each line.. I even tried Append(Enviroment.NewLine)... And I tried using only Append... then it writes everything in one line. so either I am having all values in one line or between each value one CRLF too much

EDIT: So the Output now with AppendLine is like this:

1
Empty Line
2
Empty Line
3
Empty Line

But I want it like this:

1
2
3

Upvotes: 1

Views: 1295

Answers (1)

Adrian Efford
Adrian Efford

Reputation: 483

Use a line separator ("\n")


sb.Append(data.toString + "\n");

Upvotes: 0

Related Questions