Need to create a string token dynamically base on which method is calling it

Posted by sa on Stack Overflow See other posts from Stack Overflow or by sa
Published on 2009-09-15T18:35:39Z Indexed on 2010/03/30 16:03 UTC
Read the original article Hit count: 224

Filed under:

This is a minimal code.

I have the string Str which is used by various methods. I want to in getId method be able to do 2 things

  1. Assign class="PDP" to it and
  2. Give it a value3

So the final string looks like

<tr class='PDP' id='{2}'> <td {0}</td><td>{1}</td></tr>

But please note that I will need different values for class in different methods so some Str will have PDP, another will have PTM etc. Is there a clean way to achieve this .

private const string Str = "<tr><td >{0}</td><td>{1}</td></tr>";

public static string getId()
{
  string  field=string.Format(str, value1,value2, found=true? value3:"");
}

© Stack Overflow or respective owner

Related posts about ASP.NET