C# Environment ExpandEnvironmentVariables
Description
Environment ExpandEnvironmentVariables
replaces
the name of each environment variable embedded in the specified string with
the string equivalent of the value of the variable, then returns the resulting
string.
Syntax
Environment.ExpandEnvironmentVariables
has the following syntax.
public static string ExpandEnvironmentVariables(
string name
)
Parameters
Environment.ExpandEnvironmentVariables
has the following parameters.
name
- A string containing the names of zero or more environment variables. Each environment variable is quoted with the percent sign character (%).
Returns
Environment.ExpandEnvironmentVariables
method returns A string with each environment variable replaced by its value.
Example
The following example shows how to obtain the system drive and system root variables.
/* w w w . j av a 2 s . c om*/
using System;
class Sample
{
public static void Main()
{
String str;
String nl = Environment.NewLine;
String query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
str = Environment.ExpandEnvironmentVariables(query);
Console.WriteLine("ExpandEnvironmentVariables: {0} {1}", nl, str);
}
}
The code above generates the following result.