Replace name of each environment variable embedded in the specified string with the string equivalent of the value of the variable in CSharp

Description

The following code shows how to replace name of each environment variable embedded in the specified string with the string equivalent of the value of the variable.

Example


//from w ww  .  ja v a 2 s.  c o  m
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.





















Home »
  C# Tutorial »
    Development »




Console
Encoding
Environment
Random