C#字符串格式化处理

string name = "Alex";
            int age = 18;
            Console.WriteLine("name:{0},age:{1}",name,age);
            Console.Read();

string name = "Alex";
            int age = 18;
            string input = "name:{0},age:{1}";
            string output = string.Format(input, name, age);
            Console.WriteLine(output);


 //字符串内嵌,用于模版较多的情况
            string name = "Alex";
            int age = 18;
            string input = $"name:{name},age:{age}";
            //string output = string.Format(input, name, age);
            Console.WriteLine(input);


 //原意字符串,保持字符串原始状态
            string name = "Alex";
            int age = 18;
            string input = @"name:{0}\n age:{1}\n";
            string output = string.Format(input, name, age);
            Console.WriteLine(output);

你可能感兴趣的:(c#,前端,javascript)