iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >C#Replace替换的具体使用
  • 934
分享到

C#Replace替换的具体使用

C#Replace替换C#Replace 2023-02-19 09:02:31 934人浏览 独家记忆
摘要

目录前言一、String.Replace() 的几个重载1、Replace(Char, Char)2、String.Replace(String, String) 

前言

Replace 的作用就是,通过指定内容的替换,返回一个新字符串

返回值中,已将当前字符串中的指定 Unicode 字符或 String 的 所有匹配项,替换为指定的新的 Unicode 字符或 String。

一、String.Replace() 的几个重载

String.Replace() 总共有四个重载,分别是:(详见官网:String.Replace 方法)

  • Replace(Char, Char)、
  • Replace(String, String)、
  • Replace(String, String, StringComparison)、
  • Replace(String, String, Boolean, CultureInfo)。

下面来逐个简单介绍下。

1、Replace(Char, Char)

// 作用:
// 将实例中出现的所有指定 Unicode 字符都替换为另一个指定的 Unicode 字符。
// 语法:
public string Replace (char oldChar, char newChar);

代码示例:

String str = "1 2 3 4 5 6 7 8 9";
Console.WriteLine($"Original string: {str}");
Console.WriteLine($"CSV string:      {str.Replace(' ', ',')}");
// 输出结果:
// Original string: "1 2 3 4 5 6 7 8 9"
// CSV string:      "1,2,3,4,5,6,7,8,9"

现在补充一下关于 Char 类型:

char 类型关键字是 .net System.Char 结构类型的别名,它表示 Unicode UTF-16 字符。

类型范围大小.NET 类型默认值
charU+0000 到 U+FFFF16 位System.Char\0 即 U+0000
// 给 Char 类型的变量赋值可以通过多重方式,如下:
var chars = new[]
{
    'j',        //字符文本
    '\u006A',   //Unicode 转义序列,它是 \u 后跟字符代码的十六进制表示形式(四个符号)
    '\x006A',   //十六进制转义序列,它是 \x 后跟字符代码的十六进制表示形式
    (char)106,  //将字符代码的值转换为相应的 char 值
};
Console.WriteLine(string.Join(" ", chars));
// 输出的值相同: j j j j

char 类型可隐式转换为以下整型类型:ushort、int、uint、long 和 ulong。

也可以隐式转换为内置浮点数值类型:float、double 和 decimal。

可以显式转换为 sbyte、byte 和 short 整型类型。

2、String.Replace(String, String)

// 作用:
// 实例中出现的所有指定字符串都替换为另一个指定的字符串
// 语法:
public string Replace (char oldString, char newString);

示例:

// 目的:将错误的单词更正
string errString = "This docment uses 3 other docments to docment the docmentation";
Console.WriteLine($"The original string is:{Environment.NewLine}'{errString}'{Environment.NewLine}");
// 正确的拼写应该为 "document"
string correctString = errString.Replace("docment", "document");
Console.WriteLine($"After correcting the string, the result is:{Environment.NewLine}'{correctString}'");
// 输出结果:
// The original string is:
// 'This docment uses 3 other docments to docment the docmentation'
//
// After correcting the string, the result is:
// 'This document uses 3 other documents to document the documentation'
//

 另一个示例:

// 可进行连续多次替换操作
String s = "aaa";
Console.WriteLine($"The initial string: '{s}'");
s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d");
Console.WriteLine($"The final string: '{s}'");
// 如果 newString 为 null,则将 oldString 的匹配项全部删掉
s = s.Replace("dd", null);
Console.WriteLine($"The new string: '{s}'");

// 输出结果:
//The initial string: 'aaa'
//The final string: 'DDD'
//The new string: 'd'

 3、Replace(String, String, StringComparison)

相较于上一个重载,新增了一个入参枚举类型 StringComparison(详见官网:StringComparison 枚举)。作用是:指定供 Compare(String, String) 和 Equals(Object) 方法的特定重载,使用的区域性、大小写和排序规则。

相关源代码如下,可以看出,不同的 StringComparison 参数值对应的操作不同,最主要的区别就是是否添加参数 CultureInfo。

public string Replace(string oldValue, string? newValue, StringComparison comparisonType)
{
	switch (comparisonType)
	{
		case StringComparison.CurrentCulture:
		case StringComparison.CurrentCultureIgnoreCase:
			return ReplaceCore(oldValue, newValue, CultureInfo.CurrentCulture.CompareInfo, 
                               GetCaseCompareOfComparisonCulture(comparisonType));
		case StringComparison.InvariantCulture:
		case StringComparison.InvariantCultureIgnoreCase:
			return ReplaceCore(oldValue, newValue, CompareInfo.Invariant, 
                               GetCaseCompareOfComparisonCulture(comparisonType));
		case StringComparison.Ordinal:
			return Replace(oldValue, newValue);
		case StringComparison.OrdinalIgnoreCase:
			return ReplaceCore(oldValue, newValue, CompareInfo.Invariant, CompareOptions.OrdinalIgnoreCase);
		default:
			throw new ArgumentException(SR.NotSupported_StringComparison, "comparisonType");
	}
}

关于不同区域的不同 CultureInfo 实例,程序运行结果的区别,见下面的示例:

// 以下示例为三种语言("zh-CN", "th-TH", "tr-TR")不同枚举值的测试代码和输出结果:
String[] cultureNames = { "zh-CN", "th-TH", "tr-TR" }; // 中国 泰国 土耳其
String[] strings1 = { "a", "i", "case", };
String[] strings2 = { "a-", "\u0130", "Case" };
StringComparison[] comparisons = (StringComparison[])Enum.GetValues(typeof(StringComparison));
foreach (var cultureName in cultureNames)
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
    Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
    for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++)
    {
        foreach (var comparison in comparisons)
            Console.WriteLine("   {0} = {1} ({2}): {3}", strings1[ctr], strings2[ctr], comparison,
                              String.Equals(strings1[ctr], strings2[ctr], comparison));
        Console.WriteLine();
    }
    Console.WriteLine();
}

// 输出结果:
// Current Culture: zh-CN
//    a = a- (CurrentCulture): False //-----注意------
//    a = a- (CurrentCultureIgnoreCase): False //-----注意------
//    a = a- (InvariantCulture): False
//    a = a- (InvariantCultureIgnoreCase): False
//    a = a- (Ordinal): False
//    a = a- (OrdinalIgnoreCase): False
// 
//    i = İ (CurrentCulture): False
//    i = İ (CurrentCultureIgnoreCase): False //-----注意------
//    i = İ (InvariantCulture): False
//    i = İ (InvariantCultureIgnoreCase): False
//    i = İ (Ordinal): False
//    i = İ (OrdinalIgnoreCase): False
// 
//    case = Case (CurrentCulture): False
//    case = Case (CurrentCultureIgnoreCase): True
//    case = Case (InvariantCulture): False
//    case = Case (InvariantCultureIgnoreCase): True
//    case = Case (Ordinal): False
//    case = Case (OrdinalIgnoreCase): True
// 
// 
// Current Culture: th-TH
//    a = a- (CurrentCulture): True //-----注意------
//    a = a- (CurrentCultureIgnoreCase): True //-----注意------
//    a = a- (InvariantCulture): False
//    a = a- (InvariantCultureIgnoreCase): False
//    a = a- (Ordinal): False
//    a = a- (OrdinalIgnoreCase): False
// 
//    i = İ (CurrentCulture): False
//    i = İ (CurrentCultureIgnoreCase): False
//    i = İ (InvariantCulture): False
//    i = İ (InvariantCultureIgnoreCase): False
//    i = İ (Ordinal): False
//    i = İ (OrdinalIgnoreCase): False
// 
//    case = Case (CurrentCulture): False
//    case = Case (CurrentCultureIgnoreCase): True
//    case = Case (InvariantCulture): False
//    case = Case (InvariantCultureIgnoreCase): True
//    case = Case (Ordinal): False
//    case = Case (OrdinalIgnoreCase): True
// 
// 
// Current Culture: tr-TR
//    a = a- (CurrentCulture): False
//    a = a- (CurrentCultureIgnoreCase): False
//    a = a- (InvariantCulture): False
//    a = a- (InvariantCultureIgnoreCase): False
//    a = a- (Ordinal): False
//    a = a- (OrdinalIgnoreCase): False
// 
//    i = İ (CurrentCulture): False
//    i = İ (CurrentCultureIgnoreCase): True //-----注意------
//    i = İ (InvariantCulture): False
//    i = İ (InvariantCultureIgnoreCase): False
//    i = İ (Ordinal): False
//    i = İ (OrdinalIgnoreCase): False
// 
//    case = Case (CurrentCulture): False
//    case = Case (CurrentCultureIgnoreCase): True
//    case = Case (InvariantCulture): False
//    case = Case (InvariantCultureIgnoreCase): True
//    case = Case (Ordinal): False
//    case = Case (OrdinalIgnoreCase): True

4、Replace(String, String, Boolean, CultureInfo)

此重载主要介绍下后两个入参。

Boolean:布尔类型入参,默认 false。true:忽略大小写;false:区分大小写。

CultureInfo:指定代码的区域性,允许为 null,但必须站位。为空时当前区域(CultureInfo.CurrentCulture.CompareInfo)。

注:关于 CultureInfo 的详细测试示例,详见上一部分中的折叠代码。

以下是当前重载的部分源码

public string Replace(string oldValue, string? newValue, bool ignoreCase, CultureInfo? culture)
{
	return ReplaceCore(oldValue, newValue, culture?.CompareInfo, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
}
private string ReplaceCore(string oldValue, string newValue, CompareInfo ci, CompareOptions options)
{
	if ((object)oldValue == null)
	{
		throw new ArgumentNullException("oldValue");
	}
	if (oldValue.Length == 0)
	{
		throw new ArgumentException(SR.Argument_StringZeroLength, "oldValue");
	}
	return ReplaceCore(this, oldValue.AsSpan(), newValue.AsSpan(), ci ?? CultureInfo.CurrentCulture.CompareInfo, options) ?? this;
}
private static string ReplaceCore(ReadOnlySpan<char> searchSpace, ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue, CompareInfo compareInfo, CompareOptions options)
{
	Span<char> initialBuffer = stackalloc char[256];
	ValueStringBuilder valueStringBuilder = new ValueStringBuilder(initialBuffer);
	valueStringBuilder.EnsureCapacity(searchSpace.Length);
	bool flag = false;
	while (true)
	{
		int matchLength;
		int num = compareInfo.IndexOf(searchSpace, oldValue, options, out matchLength);
		if (num < 0 || matchLength == 0)
		{
			break;
		}
		valueStringBuilder.Append(searchSpace.Slice(0, num));
		valueStringBuilder.Append(newValue);
		searchSpace = searchSpace.Slice(num + matchLength);
		flag = true;
	}
	if (!flag)
	{
		valueStringBuilder.Dispose();
		return null;
	}
	valueStringBuilder.Append(searchSpace);
	return valueStringBuilder.ToString();
}

二、Regex.Replace() 的几个常用重载

1、Replace(String, String)

在指定的输入字符串(input)内,使用指定的替换字符串(replacement),替换与某个正则表达式模式(需要在实例化 Regex 对象时,将正则表达式传入)匹配的所有的字符串。

// 语法
public string Replace (string input, string replacement);

下面是一个简单的示例:

// 目的是将多余的空格去掉
string input = "This is   text with   far  too   much   white space.";
string pattern = "\\s+"; // \s:匹配任何空白字符;+:匹配一次或多次
string replacement = " ";
Regex rgx = new Regex(pattern); // 实例化时传入正则表达式
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
// 输出结果:
// Original String: This is   text with   far  too   much   white space.
// Replacement String: This is text with far too much white space.

 2、Replace(String, String, String)

在指定的输入字符串内(input),使用指定的替换字符串(replacement)替换与指定正则表达式(pattern)匹配的所有字符串。

// 语法:
public static string Replace (string input, string pattern, string replacement);
// 目的:将多余的空格去掉
string input = "This is   text with   far  too   much   white space.";
string pattern = "\\s+"; 
// 注:\s  匹配任何空白字符,包括空格、制表符、换页符等
// 注:+   重复一次或多次
string replacement = " "; // 将连续出现的多个空格,替换为一个
string result = Regex.Replace(input, pattern, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
// 输出结果:
//Original String: This is text with   far too   much white space.
//Replacement String: This is text with far too much white space.

3、Replace(String, String, Int32, Int32)

在指定输入子字符串(input)内,使用指定替换字符串(replacement)替换与某个正则表达式模式匹配的字符串(其数目为指定的最大数目)。startat 是匹配开始的位置。

// 语法:
public string Replace (string input, string replacement, int count, int startat);

 下面是一个示例:

// 目的:添加双倍行距
string input = "Instantiating a New Type\n" +
    "Generally, there are two ways that an\n" +
    "instance of a class or structure can\n" +
    "be instantiated. ";
Console.WriteLine("原内容:");
Console.WriteLine(input);
// .:匹配除‘\n'之外的任何单个字符;*:匹配零次或多次
string pattern = "^.*$"; // ^.*$ 在这里就是匹配每一行中‘\n'前边的字符串
string replacement = "\n$&"; // 在匹配项前添加‘\n';$&:代表匹配内容
Regex rgx = new Regex(pattern, RegexOptions.Multiline); // Multiline:多行模式,不仅仅在整个字符串的开头和结尾匹配
string result = string.Empty;
Match match = rgx.Match(input); // 判断能否匹配
if (match.Success)
    result = rgx.Replace(input, 
                         replacement,
                         -1, // >= 0 时,就是匹配具体次数,= -1 时就是不限制次数
                         match.Index + match.Length + 1 // 作用就是跳过第一个匹配项(第一行不做处理)
                         // 当第一次匹配时:Index=0,length=除了‘\n'之外的长度,最后再 +1 就是第一行全部的内容
                        );
Console.WriteLine("结果内容:");
Console.WriteLine(result);
// 输出结果:
// 原内容:
// Instantiating a New Type
// Generally, there are two ways that an
// instance of a class or structure can
// be instantiated.
// 结果内容:
// Instantiating a New Type
// 
// Generally, there are two ways that an
// 
// instance of a class or structure can
// 
// be instantiated.

4、Replace(String, String, MatchEvaluator, RegexOptions, TimeSpan)

在入参字符串(input)中,进行正则表达式(pattern)的匹配,匹配成功的,传递给 MatchEvaluator 委托(evaluator)处理完成后,替换原匹配值。

RegexOptions 为匹配操作配置项(关于 RegexOptions 详见官网:RegexOptions 枚举),TimeSpan 为超时时间间隔。

public static string Replace (string input, string pattern, 
                              System.Text.RegularExpressions.MatchEvaluator evaluator, 
                              System.Text.RegularExpressions.RegexOptions options, 
                              TimeSpan matchTimeout);

下面是一个示例:

// 目的:将输入的每个单词中的字母顺序随机打乱,再一起输出
static void Main(string[] args)
{
    string Words = "letter alphabetical missing lack release " +
        "penchant slack acryllic laundry cease";
    string pattern = @"\w+  # Matches all the characters in a word.";
    MatchEvaluator evaluator = new MatchEvaluator(WordScrambler); // WordScrambler:回调函数
    Console.WriteLine("Original words:");
    Console.WriteLine(words);
    Console.WriteLine();
    try
    {
        Console.WriteLine("Scrambled words:");
        Console.WriteLine(Regex.Replace(words, pattern, evaluator,
                RegexOptions.IgnorePatternWhitespace, TimeSpan.FromSeconds(2)));
    }
    catch (RegexMatchTimeoutException)
    {
        Console.WriteLine("Word Scramble operation timed out.");
        Console.WriteLine("Returned words:");
    }
}
/// <summary>
/// 回调:对全部匹配项逐一进行操作
/// </summary>
/// <param name="match"></param>
/// <returns></returns>
public static string WordScrambler(Match match)
{
    int arraySize = match.Value.Length;
    double[] keys = new double[arraySize]; // 存放随机数
    char[] letters = new char[arraySize]; // 存放字母
    Random rnd = new Random();
    for (int ctr = 0; ctr < match.Value.Length; ctr++)
    {
        keys[ctr] = rnd.NextDouble(); // 生成随机数,用于重新排序
        letters[ctr] = match.Value[ctr]; // 将输入参单词数拆解为字母数组
    }
    Array.Sort(keys, letters, 0, arraySize, Comparer.Default); // 重新根据随机数大小排序
    return new String(letters);
}
// 输出结果:
// Original words:
// letter alphabetical missing lack release penchant slack acryllic laundry cease
// 
// Scrambled words:
// eltetr aeplbtaiaclh ignisms lkac elsaree nchetapn acksl lcyaricl udarnly casee

三、关于 Replace 的实际需求简单示例

1、全部替换匹配项

string input = "Instantiating Instantiating Instantiating Instantiating";
Console.WriteLine("----原内容----");
Console.WriteLine(input);
string result = input.Replace("tiating","*******");
Console.WriteLine("----结果内容----");
Console.WriteLine(result);
// ----原内容----
// Instantiating Instantiating Instantiating Instantiating
// ----结果内容----
// Instan******* Instan******* Instan******* Instan*******

2、仅替换第一个匹配项

string input = "Instantiating Instantiating Instantiating Instantiating";
Console.WriteLine("----原内容----");
Console.WriteLine(input);
Regex regex = new Regex("tiating");
string result = regex.Replace(input, "*******",1);
Console.WriteLine("----结果内容----");
Console.WriteLine(result);
// ----原内容----
// Instantiating Instantiating Instantiating Instantiating
// ----结果内容----
// Instan******* Instantiating Instantiating Instantiating

3、仅替换最后一个匹配项

string input = "Instantiating Instantiating Instantiating Instantiating";
Console.WriteLine("----原内容----");
Console.WriteLine(input);
Match match = Regex.Match(input, "tiating",RegexOptions.RightToLeft);
string first = input.Substring(0, match.Index);
string last = input.Length == first.Length + match.Length ? "" : 
input.Substring(first.Length + match.Length,input.Length-(first.Length + match.Length));
string result = $"{first}*******{last}";
Console.WriteLine("----结果内容----");
Console.WriteLine(result);
// 两次测试结果:
// ----原内容----
// Instantiating Instantiating Instantiating Instantiating 345
// ----结果内容----
// Instantiating Instantiating Instantiating Instan******* 345
// ----原内容----
// Instantiating Instantiating Instantiating Instantiating
// ----结果内容----
// Instantiating Instantiating Instantiating Instan*******

参考:String.Replace 方法

     Regex.Replace 方法

到此这篇关于C# Replace替换的具体使用的文章就介绍到这了,更多相关C# Replace替换内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: C#Replace替换的具体使用

本文链接: https://www.lsjlt.com/news/196742.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • C#Replace替换的具体使用
    目录前言一、String.Replace() 的几个重载1、Replace(Char, Char)2、String.Replace(String, String) ...
    99+
    2023-02-19
    C# Replace替换 C# Replace
  • sql替换函数replace如何使用
    SQL中的REPLACE函数用于将字符串中的指定字符或字符串替换为新的字符或字符串。语法:```REPLACE(string, ol...
    99+
    2023-09-13
    sql
  • R语言gsub替换字符工具的具体使用
    gsub()可以用于字段的删减、增补、替换和切割,可以处理一个字段也可以处理由字段组成的向量。 具体的使用方法为:gsub("目标字符", "替换字符", 对象) 在gsub函数中,...
    99+
    2022-11-11
  • SQLite使用replace替换字段中的字符
    在SQLite中,可以使用REPLACE函数来替换字段中的字符。假设有一个名为"users"的表,其中有一个名为"name"的字段,...
    99+
    2023-09-12
    SQL
  • php中replace正则替换方法的使用
    本篇内容主要讲解“php中replace正则替换方法的使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php中replace正则替换方法的使用”吧!php replace函数用于执行一个正则表...
    99+
    2023-06-20
  • 怎么用replace替换正在使用的文件
    这篇文章主要介绍“怎么用replace替换正在使用的文件”,在日常操作中,相信很多人在怎么用replace替换正在使用的文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用replace替换正在使用的文件...
    99+
    2023-06-09
  • python如何使用replace做多字符替换
    目录使用replace做多字符替换批量替换字符串内容问题描述解决方案内置方法使用replace做多字符替换 import re words = ''' 钟声...
    99+
    2022-11-11
  • sql中怎么使用replace替换多个字符
    在SQL中,可以使用`REPLACE`函数来替换多个字符。语法如下:```sqlREPLACE(string, old_su...
    99+
    2023-09-29
    SQL
  • Python replace()函数使用详解,Python替换字符串
    「作者主页」:士别三日wyx 「作者简介」:CSDN top100、阿里云博客专家、华为云享专家、网络安全领域优质创作者 「推荐专栏」:小白零基础《Python入门到精通》 replace...
    99+
    2023-09-11
    python 网络安全 机器学习 人工智能
  • pandas如何使用replace()方法实现批量替换
    这篇文章给大家分享的是有关pandas如何使用replace()方法实现批量替换的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。我们在编程中进行数据的过程中,如果对于数据一个个的替换很容易的出现操作,而且效率低下。...
    99+
    2023-06-14
  • C# Volatile的具体使用
    目录​1.Overview2.Detail3.Conclusion4.Reference​1.Overview 经常研究.NET源码库的小伙伴会经常看到一个关...
    99+
    2022-11-12
  • 怎么在JavaScript中使用replace()方法替换当前页面
    怎么在JavaScript中使用replace()方法替换当前页面?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。JavaScript的特点1.JavaScript主要用来向HT...
    99+
    2023-06-14
  • 怎么在JavaScript中是使用replace()方法替换指定位置
    怎么在JavaScript中是使用replace()方法替换指定位置?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。JavaScript的作用是什么1、能够嵌入动态文本于HTML...
    99+
    2023-06-14
  • C#DataGridView行列转换的具体实现
    目录初始表格 需要进行行列转置 转换后的效果 实现代码如下 void InitTable() { var dataTable = new...
    99+
    2023-02-07
    C# DataGridView行列转换 C#datagridview行列
  • 使用正则表达式替换字符串的replace方法是什么
    这篇文章主要讲解了“使用正则表达式替换字符串的replace方法是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“使用正则表达式替换字符串的replace方法是什么”吧!正则表达式(reg...
    99+
    2023-06-03
  • javacript中如何使用replace正则取字符串中的值并替换
    这篇文章将为大家详细讲解有关javacript中如何使用replace正则取字符串中的值并替换,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。replace() 方法用于在...
    99+
    2022-10-19
  • C++ deque容器的具体使用
     deque 是 double-ended queue 的缩写,又称双端队列容器。 和 vector 不同的是,deque 还擅长在序列头部添加或删除元素,所耗费的时间复杂...
    99+
    2022-11-12
  • C# goto语句的具体使用
    C# goto 语句用于直接在一个程序中转到程序中的标签指定的位置,标签实际上由标识符加上冒号构成。 语法形式如下。 goto Labell; 语句块 1; Labell...
    99+
    2022-11-12
  • C#中{get;set;}的具体使用
    在C#程序中经常会看到set,get的配套使用,很多人不知道它的用途。我就在这向大家讲讲,也加深一下自己的印象。 //这里有两个类 public class person1 { ...
    99+
    2023-02-06
    C# {get;set;} C# GET SET
  • C++ setw()函数的具体使用
    C++ setw() 函数用于设置字段的宽度,语法格式如下: setw(n) n 表示宽度,用数字表示。 setw() 函数只对紧接着的输出产生作用。 当后面紧跟着的输出字段长度小...
    99+
    2023-03-09
    C++ setw()
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作