C# 读取环境变量,和字符串大小写转换
string.ToLower()更改大小写返回的是副本,原来的字符串还是原来的。ToUper()应该也是一样的吧;ToLower()只改变字母大小写,其他的字符不改变;- 读取(系统)环境变量时,自己新建的环境变量后,需要重启电脑,才能读取到。
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string a = "abkj_KKOIHI_1234-_!你好!!!";
Console.WriteLine(a);
string b = a.ToLower();
Console.WriteLine(b);
Console.WriteLine(a);
string str = Environment.GetEnvironmentVariable("RebSoft");// 系统环境变量
string s = Environment.GetEnvironmentVariable("RebSoft", EnvironmentVariableTarget.User); // 当前用户环境变量
Console.WriteLine(str);
Console.WriteLine(s);
Console.ReadKey();
}
}
}
输出:

这里有一篇读取环境变量的博文,很全:https://www.cnblogs.com/tianma3798/p/5500279.html。
浙公网安备 33010602011771号