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

  1. string.ToLower() 更改大小写返回的是副本,原来的字符串还是原来的。ToUper()应该也是一样的吧;
  2. ToLower()只改变字母大小写,其他的字符不改变;
  3. 读取(系统)环境变量时,自己新建的环境变量后,需要重启电脑,才能读取到。
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

posted @ 2021-09-27 13:44  double64  阅读(98)  评论(0)    收藏  举报