Re: [Vala] Handling multiline strings



On Mon, 2013-06-10 at 18:22 +0530, Satyajit Sahoo wrote:
Hi. I'm trying to write a multiline string into a file,

e.g.

string new = """Line 1 and %s

Line 2 and %s

Line 3

Line 4""".printf (var1, var2);

The problem is, when I write it to the file, the lines from the 2nd line,
have tab characters preceding them. I want to keep the idention level of
the code to improve redability. How can I make it ignore the tabs used for
code indention while writing to the file?

You can't, though instead of relying on verbatim strings you could do
something like

string foo = ("Line 1 and %s\n" +
              "Line 2 and %s\n" +
              "Line 3\n" +
              "Line 4").printf (var1, var2);

Note that method calls have a higher priority than string concatenation,
which is why I enclosed the strings in parenthesis.  Without the method
call you could just do

string foo = "Line 1 and %s\n" +
             "Line 2 and %s\n" +
             "Line 3\n" +
             "Line 4";

-Evan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]