Resource Manager, Error message, {0}...

  • Thread starter Thread starter Shikari Shambu
  • Start date Start date
S

Shikari Shambu

Hi,
I am trying to put all the error messages for an application in a
resource file so that the error messages can be reused and is consistent
across the application.

Some of the messages need contextual information like

The file '{0}' cannot be deleted from the '{1}' . Please ensure that that
file is not currently being used.



The problem I have is the number of substituation parmameters may vary for
each resoruce string. Is there a way to pass this dynamic array to the
Getstring function or the String.Format function to do the substitution?



TIA
 
Shikari Shambu said:
I am trying to put all the error messages for an application in a
resource file so that the error messages can be reused and is consistent
across the application.

Some of the messages need contextual information like

The file '{0}' cannot be deleted from the '{1}' . Please ensure that that
file is not currently being used.

The problem I have is the number of substituation parmameters may vary for
each resoruce string. Is there a way to pass this dynamic array to the
Getstring function or the String.Format function to do the substitution?

Use String.Format (formatString, parameters);

where parameters is an array. For example:

using System;

class Test
{
static void Main()
{
string formatString = "{0} is {1}";
string[] parameters = {".NET", "great"};

string result = string.Format(formatString, parameters);
Console.WriteLine (result);
}
}
 
Back
Top