C# 读取环境变量,和字符串大小写转换

  1. string.ToLower() 更改大小写返回的是副本,原来的字符串还是原来的。ToUper()应该也是一样的吧;
  2. ToLower()只改变字母大小写,其他的字符不改变;
  3. 读取(系统)环境变量时,自己新建的环境变量后,需要重启电脑,才能读取到。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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

感谢支持!