tags:

views:

37

answers:

2

i have a simple statement of code that reads:

Return String.Format("{0} {1} {2}", _var1, _var2, _var3)

i'm trying to get this formatted string to output each var on it's own line. i'm new to vb.net but i did try one thing:

"{0}\n {1}\n {2}"

that didn't work. any help?

+4  A: 

How about this:

Return String.Format( _
    "{1}{0}{2}{0}{3}{0}", _
    Environment.NewLine, _
    _var1, _
    _var2, _
    _var3 _
)

This could work too, though it's a bit "trickier":

Return New StringBuilder() _
    .AppendLine(_var1.ToString()) _
    .AppendLine(_var2.ToString()) _
    .AppendLine(_var3.ToString()) _
    .ToString()
Dan Tao
I would use your first example. Also you don't need to `ToString()` each variable for `AppendLine()`
Pondidum
@Pondidum: Well, `StringBuilder.AppendLine` takes a `String` argument, so as long as the OP has `Option Strict On` he'll need to call `ToString` unless the three variables are already of type `String` (which wasn't indicated).
Dan Tao
Ah, i was looking at `Append()` not `AppendLine()`
Pondidum
A: 

I would go with something like this:

Return String.Format("{0}{1}{2}",_var1 & vbcrlf, _var2 & vbcrlf, _var3 & vbcrlf)
knslyr
all those repeated vbcrlf and concats seem to miss the point of string.format
Pondidum