C#核心笔记——(六)框架基础
我们在编程时所需的许多核心功能并不是由C#语言提供的,而是由.NET Framework中的类型提供的。本节我们将介绍Framework在基础编程任务(例如虚的等值比较、顺序比较以及类型转换)中的作用。我们还会介绍Framework中的基本类型,例如String、DateTime和Enum.
本章中的绝大部分类型位于System命名空间下,但以下几种类型除外:
1.StringBuilder类型定义在System。Text命名空间中。该命名空间中还包含用于进行文本编码的类型。
2.CultureInfo及其相关类型定义在System.Globalization命名空间中。
2.Xmlconvert类型定义在System.Xml命名空间中。
6.1 字符串与文本处理
6.1.1 字符
C#中的一个char代表一个Unicode字符。char是System.Char的别名。在第2章中,我们介绍了如何表示char字面量,例如:
char c = 'a';
char newLine = '\n';
System.Char定义了一系列静态方法对字符处理,例如:ToUpper、ToLower和IsWhiteSpace。这些方法既可以通过System.Char类型进行调用也可以使用其别名char进行调用:
Console.WriteLine(System.Char.ToUpper('c'));
Console.WriteLine(char.IsWhiteSpace('\t'));
ToUpper和ToLower会受到最终用户语言环境的影响,这可能会导致微妙的缺陷。例如,下面的表达式在土耳其语言环境中会得到false值:
Console.WriteLine(char.ToUpper('i') == 'I');
因为在土耳其语中,char.ToUpprt(‘i’)的结果为‘Ī’。为了避免这个问题,System.Char和System.String还提供了和语言环境无关的,有Invariant后缀的ToUpper和ToLower。它们会使用英语语言规则:
Console.WriteLine(char.ToUpperInvariant('i') == 'I');
它是以下写法的简化形式:
Console.WriteLine(char.ToUpper('i',System.Globalization.CultureInfo.InvariantCulture) == 'I');
char类型中有相当一部分的静态方法用于字符分类,如表:
静态方法 | 包含的字符 | 包含的Unicode分类 |
---|---|---|
IsLetter | A-Z,a-z和其他字母字符 | UpperCaseLetter LowerCaseLetter TittleCaseLetter ModifierLetter OtherLetter |
IsUpper | 大小写字母 | UpperCaseLetter |
IsLower | 小写字母 | LowerCaseLetter |
IsDigit | 0-9和其他字母表中的数字 | DecimalDigitNumber |
IsLetterOrDigit | 字母和数字 | IsLetter、IsDigit |
IsNumber | 所有数字以及Unicode分数和罗马数字符号 | DecimalDigitNumber LetterNumber OtherNumber |
IsSeparator | 空格与所有Unicode分隔符 | LIneSeparate ParagraphSeparate |
IsWhiteSpace | 所有分隔符,以及\n、\r、\t、\f和\v | LIneSeparate ParagraphSeparate |
IsPunctuation | 西方和其他字母表中的标点符号 | DashPunchtuation Connector Punctuation InitialQuote PunctuationFinalQuotePPunctuation |
IsSymbol | 大部分其他的可打印符号 | MathSymbol ModifierSymbol OtherSymbol |
isControl | 值小于0x20的不可打印的控制字符。例如\n、\r、\t、\0和0x7F与0x9A之间的字符 | (无) |
对于更详细的分类,char提供了一个名为GetUnicodeCategory的静态方法,它返回一个UnicodeCategory枚举值,它的成员即表的6-1最右边一列的值。
我们完全由能力通过显示转换一个整数来制造出一个Unicode集之外的char。因此要检测字符的有效性,可以调用char.GetUnicodeCategory方法:如果返回值为UnicodeCategory.OhterNotAssigned那么这个字符就是无效的。
一个char字符占用16给二进制位,这足以表示基本多文种平面(Basic Multilingual Plane)中的所有Unicode字符。但是如果超出了这个范围,就必须使用替代组(Surrogate pairs)。
6.1.2 字符串
C#中的string(==System.String)是一个不可变的(不可修改)的字符序列。在第二章笔记中,我们介绍了如何表示一个字符串字面量,执行相等比较以及如何连接两个字符串。本章我们将介绍其余字符串处理函数:System.String类的静态和实例成员函数。
6.1.2.1 创建字符串
创建字符串的最简单方法就是将字面量赋给一个变量,这和我们在第2章的做法一样:
string s1 = "Hello";
string s2 = "First Line\r\nSecond Line";
string s3 = @"\\r_server\n_fileshare\t_helloworld.cs";
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
若要创建一个重复的字符序列,可以使用string类的构造器:
Console.WriteLine(new string('*',10));//**********
我们还可以从char数组来构造一个字符串,而ToCharArray方法则执行了相反的操作:
char[] ca = "Hello".ToCharArray();
string sca = new string(ca);
Console.WriteLine(sca);//Hello
string类的重载构造器可以接收各种(不安全的)指针类型,以便从类似char*这种类型中创建字符串。
6.1.2.2 null和空字符串
空字符串指长度为零的字符串。我们可以使用字面量或静态string.Empty字段来创建一个空字符串。若要判断一个字符串是否为空字符串,则可以执行一个相等比较,或测试它的Length属性:
string empty = "";
Console.WriteLine(empty == ""); //True
Console.WriteLine(empty == string.Empty); //True
Console.WriteLine(empty.Length == 0); //True
字符串是引用类型,因此它可以为null:
string nullString = null;
Console.WriteLine(nullString == null);//True
Console.WriteLine(nullString == ""); //False
Console.WriteLine(nullString.Length == 0); //NullReferenceException
我们可以使用静态方法string.IsNullOrEmpty来判断一个字符串是否为null或空字符串。
6.1.2.3 访问字符串中的字符
字符串的索引器可以返回一个指定索引位置的字符。和所有操作字符串的方法相似,索引是从0开始计数的。
string str = "abcde";
char letter = str[1];
Console.WriteLine(letter);//letter == 'b'
string还实现了IEnumerable,所以可以用foreach遍历它的字符:
foreach (char c in "abc")
{Console.Write(c + ",");//1,2,3
}
6.1.2.4 字符串内搜索
在字符串内执行搜索的最简单方法是StartsWith、EndsWith和Contains,这些方法均返回true或false:
Console.WriteLine("quick brown fox".StartsWith("quick"));//True
Console.WriteLine("quick brown fox".EndsWith("fox"));//True
Console.WriteLine("quick brown fox2".EndsWith("fox"));//false
Console.WriteLine("quick brown fox".EndsWith("fox"));//True
Console.WriteLine("quick brown fox".Contains("brown"));//True
StartsWith和EndsWith提供了重载方法,使用StringComparsion枚举或者CultureInfo对象来控制大小写和文化相关的规则。其默认行为是使用当前文化规则执行区分大小写的匹配。以下代码则使用了不变文化规则执行不区分大小写的搜索:
bool isaBc = "abcdef".StartsWith("aBc", StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine(isaBc); //True
Contains则没有提供这种便利的重载方法,但是可以使用IndexOf方法实现相同的效果。
IndexOf的功能更强,它返回指定字符或者字符串的首次出现的位置(-1则表示该子字符串不存在):
Console.WriteLine("abcdef".IndexOf("cd"));
IndexOf也提供了重载方法,不但接受StringComparison枚举值,还可以接受startPosition参数,指定初始搜索位置。
Console.WriteLine("abcde abcde".IndexOf("CD",6,StringComparison.CurrentCultureIgnoreCase));//8
LastIndexOf和IndexOf类似,只是它从后向前进行搜索的。
IndexOfAny返回和字符集中的任意一个字符第一个匹配的位置:
Console.WriteLine("ab,cd ef".IndexOfAny(new char[] { ' ',','}));//2
Console.WriteLine("pas5wOrd".IndexOfAny("0123456789".ToCharArray()));//3
LastIndexOfAny则从相反方向执行相同操作。
6.1.2.5 字符串处理
string是不可变的,因此所有“处理”字符串的方法都会返回一个新的字符串,而原始的字符串则不受影响(其效果和重新为一个字符串变量赋值一样)。
Substring方法可以提取部分字符串:
string left3 = "12345".Substring(0,3);
string mid3 = "12345".Substring(1,3);
Console.WriteLine(left3);//123
Console.WriteLine(mid3);//234
若省略长度,则会得到剩余的字符串:
string end3 = "12345".Substring(2);
Console.WriteLine(end3);//345
Insert和Remove在特定的位置插入或者删除一些字符:
string s1 = "helloworld".Insert(5, ",");
Console.WriteLine(s1); //hello,world
string s2 = s1.Remove(5, 2);
Console.WriteLine(s2); //helloorld
PadLeft和PadRight会特定的字符(如果未指定则使用空格)将字符串填充为指定的长度:
Console.WriteLine("12345".PadLeft(9,'*')); //****12345
Console.WriteLine("12345".PadLeft(9));// 12345
如果输入字符串长度大于填充长度,则返回不发生变化的原始字符串。
TrimStart和TrimEnd会从字符串的开始或结尾删除指定的字符,Trim则是从开始和结尾执行删除操作。这些方法默认会删除空白字符(包括空格、制表符、换行和这些字符的Unicode变体):
Console.WriteLine(" abc \t\r\n ".Trim().Length);//3
Replace会替换字符串中所有(非重叠的)特定字符或子字符串:
Console.WriteLine("to be done".Replace(" "," | "));//to | be |done
Console.WriteLine("to be done".Replace(" ", ""));//tobedone
ToUpper和ToLower会返回与输入字符串相对应的大写和小写字符串。默认情况下,它会受用户当前语言设置的影响;ToUpperInvariant和ToLowerInvariant则总是应用英语字母表规则。
6.1.2.6 字符串的分割与连接
Split将字符串分割为若干部分:
string[] words = "The quick brown fox".Split();foreach (string word in words)Console.Write(word + "|"); //The|quick|brown|fox|
默认情况下,Split使用空白字符作为分隔符;重载的方法也可以接收char和string分隔符的params数组。Split还可以接受一个StringSplitOptions枚举值以删除空白项。这在一行文本中有多种单词分隔符时很有用。
静态方法Join则执行和Split相反的操作。它需要一个分隔符和字符串的数组:
string[] words = "The quick brown fox".Split();
string together = string.Join(",", words);
Console.WriteLine(together);//The,quick,brown,fox
静态方法Concat和Join类似,但是它仅仅接受一个字符串的params数组,且不支持分隔符。Concat操作和+操作符效果完全相同(实际上编译器会将+转换为Concat):
string sentence = string.Concat("The", "quick", "brown", "fox");
string sameSentence = "The" + "quick" + "brown" + "fox";
Console.WriteLine(sentence);//Thequickbrownfox
Console.WriteLine(sameSentence);//Thequickbrownfox
6.1.2.7 String.Format与组合格式字符串
静态方法Format提供了创建嵌入变量的字符串的便利方法。嵌入的变量(或值)可以时任何类型,而Format则会直接调用它们的ToString方法。
包含嵌入变量的主字符串称为组合格式字符串。调用String.Format时,需要提供一个组合格式字符串,后面紧跟每一个嵌入的变量,例如:
string composite = "It's {0} degrees in {1} on this{2}morning";
string s = string.Format(composite, 35, "Perth", DateTime.Now.DayOfWeek);
Console.WriteLine(s); //It 's 35 degrees in Perth on thisSaturdaymorning
从C#6开始,可以使用插值字符串字面量来达成同样的效果。只需要在字符串前面加上$符号,并将表达式写在花括号中:
string s = $"It's hot this{DateTime.Now.DayOfWeek} morning";
Console.WriteLine(s);
花括号里面的每一个数字称为格式项。这些数字对应参数的位置,后面可以跟随:
1.逗号与应用的最小宽度
2.冒号与格式字符串
3.最小宽度用于对齐各个列。如果其值为负数,则左对齐,否则为右对齐,例如:
string composite = "Name={0,-20} Credit Limit={1,15:C}";
Console.WriteLine(string.Format(composite,"Mary",500));
Console.WriteLine(string.Format(composite, "Elizabeth", 20000));
运行结果:
Name=Mary Credit Limit= ¥500.00
Name=Elizabeth Credit Limit= ¥20,000.00
如果不使用string.Format则上述方法可写为:
string composites = "Name=" + "Mary".PadRight(20) + "Credit Limit"+ 500.ToString("C").PadLeft(15);
Console.WriteLine(composites);
上例的信用额度是通过”C“格式字符串转换为货币值的。
6.1.3 字符串的比较
.NET Framework在两个值的比较上划分了两个不同的概念:相等比较和顺序比较。等值比较验证两个实例是否从语义上是相同的,而顺序比较则验证两个实例(如果有的话)按照升序或者降序排列的话,哪一个应当首先出现。
等值比较并不是顺序比较的一个子集。这两种方法各自有不同的用途。例如,两个不同的值却可以有相同的排序位置。
可以使用==操作符或者string的Equals方法来进行字符串的等值比较。后者可以指定一些选项*例如不区分大小写),因此功能更强。
另一个不同点是,如果将变量转换为object类型,则==就不一定是按字符串处理的了。
对于字符串的顺序比较则可使用实例方法CompareTo或者静态方法Compare或CompareOrdinal:这些方法会返回一个正数、负数或者0.这取决于第一个值是在第二个值之后、之前还是同时出现。
6.1.3.1 序列比较于文化相关的字符串比较
字符串比较有两种基本方法:序列比较(ordinal)和文化相关的比较(culture-sensitive)。序列比较会直接将字符串解析为数字(按照它们的Unicode字符数值);而文化相关的比较则参照特定的字母表来解释字符。有两种特殊的文化:”当前文化“,基于计算机控制面板的设定;”不变文化“,在任何计算机上都是相同的(并且和美国文化密切一致)。
对于相等比较,序列和文化相关的算法都是非常有用的。而排序时,人们则通常选择文化相关的比较:因为当按照字符进行排序时,通常需要一个字母顺序表。序列比较依赖的是Unicode的数字位置,这恰好会使英文字母按照顺序排序,但即使是这样也可能不能满足要求。例如,在区分大小写的情况下,考虑如下字符串”Atom“、”autom"和“Zamia"。使用不变文化则其排列顺序将是:
"autom"、"Atom"、"Zamia"
而使用序列比较则为:
"Atom"、"Zamia"、"autom"
这是因为不变文化封装了一个字母表,它认为大写字符与其对应的小写字符是相邻的(aAbBcCdD…)。然而序列比较算法将所有大写字母排列在前面,然后才是全部小写字母(A…Z,a…z)这实际上回归到了20世纪60年代发明的ASCII字符集了。
6.1.3.2 字符串的相等比较
结果序列比较有局限性,但是字符串的==运算符总是执行区分大小写的序列比较。不带有参数的string.Equals方法也是用同样的方式。这就是string类型的”默认“相等比较的行为。
字符串的==和Equals方法选择序列算法的原因是因为它既高效有确定。字符串相等比较是基础操作,并远比顺序比较使用频繁。
”严格“的相等概念与==运算符的一般用途是一致的。
下面的方法允许执行文化相关的大小写比较:
public bool Equals(string value, StringComparison comparisonType);
public static bool Equals(string a, string b, StringComparison comparisonType);
我们更推荐静态的版本因为它在两个字符串中的一个或者全部为null的时候仍然有效。
StringComparison是枚举类型,其定义如下:
//// 摘要:// Specifies the culture, case, and sort rules to be used by certain overloads of// the System.String.Compare(System.String,System.String) and System.String.Equals(System.Object)// methods.public enum StringComparison{//// 摘要:// Compare strings using culture-sensitive sort rules and the current culture.CurrentCulture = 0,//// 摘要:// Compare strings using culture-sensitive sort rules, the current culture, and// ignoring the case of the strings being compared.CurrentCultureIgnoreCase = 1,//// 摘要:// Compare strings using culture-sensitive sort rules and the invariant culture.InvariantCulture = 2,//// 摘要:// Compare strings using culture-sensitive sort rules, the invariant culture, and// ignoring the case of the strings being compared.InvariantCultureIgnoreCase = 3,//// 摘要:// Compare strings using ordinal (binary) sort rules.Ordinal = 4,//// 摘要:// Compare strings using ordinal (binary) sort rules and ignoring the case of the// strings being compared.OrdinalIgnoreCase = 5}
例如:
Console.WriteLine(string.Equals("foo","FOO", StringComparison.OrdinalIgnoreCase));
Console.WriteLine(" " == "ǖ");
Console.WriteLine(string.Equals(" ", "ǖ", StringComparison.CurrentCulture));
上述中的第三个比较是由计算机当前语言设置决定的。
6.1.3.3 字符串的顺序比较
String的实例方法CompareTo执行文化相关的区分大小写的顺序比较,与==运算符不同,CompareTo不使用序列比较。这是因为对于排序来说,文化相关的算法更为有效。
以下是方法的定义:
public int CompareTo(string strB);
实例方法CompareTo实现了IComparable泛型接口,它也是在整个.NET Framework中使用的标准比较协议。这意味着string的CompareTo定义了字符串在应用程序中,作为集合元素时排序的默认行为。
对于其他类型的比较则可以调用静态方法Compare和CompareOrdinal:
//// 摘要:// Compares substrings of two specified System.String objects, ignoring or honoring// their case, and returns an integer that indicates their relative position in// the sort order.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The position of the substring within strA.//// strB:// The second string to use in the comparison.//// indexB:// The position of the substring within strB.//// length:// The maximum number of characters in the substrings to compare.//// ignoreCase:// true to ignore case during the comparison; otherwise, false.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero – The substring in strA precedes the substring in strB in the// sort order.// Zero – The substrings occur in the same position in the sort order, or length// is zero.// Greater than zero – The substring in strA follows the substring in strB in the// sort order.//// 异常:// T:System.ArgumentOutOfRangeException:// indexA is greater than strA.System.String.Length. -or- indexB is greater than// strB.System.String.Length. -or- indexA, indexB, or length is negative. -or- Either// indexA or indexB is null, and length is greater than zero.public static int Compare(String? strA, int indexA, String? strB, int indexB, int length, bool ignoreCase);//// 摘要:// Compares substrings of two specified System.String objects and returns an integer// that indicates their relative position in the sort order.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The position of the substring within strA.//// strB:// The second string to use in the comparison.//// indexB:// The position of the substring within strB.//// length:// The maximum number of characters in the substrings to compare.//// 返回结果:// A 32-bit signed integer indicating the lexical relationship between the two comparands.// Value – Condition// Less than zero – The substring in strA precedes the substring in strB in the// sort order.// Zero – The substrings occur in the same position in the sort order, or length// is zero.// Greater than zero – The substring in strA follows the substring in strB in the// sort order.//// 异常:// T:System.ArgumentOutOfRangeException:// indexA is greater than strA.System.String.Length. -or- indexB is greater than// strB.System.String.Length. -or- indexA, indexB, or length is negative. -or- Either// indexA or indexB is null, and length is greater than zero.public static int Compare(String? strA, int indexA, String? strB, int indexB, int length);//// 摘要:// Compares two specified System.String objects using the specified comparison options// and culture-specific information to influence the comparison, and returns an// integer that indicates the relationship of the two strings to each other in the// sort order.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// culture:// The culture that supplies culture-specific comparison information. If culture// is null, the current culture is used.//// options:// Options to use when performing the comparison (such as ignoring case or symbols).//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between strA// and strB, as shown in the following table// Value – Condition// Less than zero –strA precedes strB in the sort order.// Zero –strA occurs in the same position as strB in the sort order.// Greater than zero –strA follows strB in the sort order.//// 异常:// T:System.ArgumentException:// options is not a System.Globalization.CompareOptions value.public static int Compare(String? strA, String? strB, CultureInfo? culture, CompareOptions options);//// 摘要:// Compares two specified System.String objects, ignoring or honoring their case,// and using culture-specific information to influence the comparison, and returns// an integer that indicates their relative position in the sort order.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// ignoreCase:// true to ignore case during the comparison; otherwise, false.//// culture:// An object that supplies culture-specific comparison information. If culture is// null, the current culture is used.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero –strA precedes strB in the sort order.// Zero –strA occurs in the same position as strB in the sort order.// Greater than zero –strA follows strB in the sort order.public static int Compare(String? strA, String? strB, bool ignoreCase, CultureInfo? culture);//// 摘要:// Compares two specified System.String objects, ignoring or honoring their case,// and returns an integer that indicates their relative position in the sort order.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// ignoreCase:// true to ignore case during the comparison; otherwise, false.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero –strA precedes strB in the sort order.// Zero –strA occurs in the same position as strB in the sort order.// Greater than zero –strA follows strB in the sort order.public static int Compare(String? strA, String? strB, bool ignoreCase);//// 摘要:// Compares two specified System.String objects using the specified rules, and returns// an integer that indicates their relative position in the sort order.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// comparisonType:// One of the enumeration values that specifies the rules to use in the comparison.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero –strA precedes strB in the sort order.// Zero –strA is in the same position as strB in the sort order.// Greater than zero –strA follows strB in the sort order.//// 异常:// T:System.ArgumentException:// comparisonType is not a System.StringComparison value.//// T:System.NotSupportedException:// System.StringComparison is not supported.public static int Compare(String? strA, String? strB, StringComparison comparisonType);//// 摘要:// Compares substrings of two specified System.String objects using the specified// rules, and returns an integer that indicates their relative position in the sort// order.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The position of the substring within strA.//// strB:// The second string to use in the comparison.//// indexB:// The position of the substring within strB.//// length:// The maximum number of characters in the substrings to compare.//// comparisonType:// One of the enumeration values that specifies the rules to use in the comparison.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero – The substring in strA precedes the substring in strB in the// sort order.// Zero – The substrings occur in the same position in the sort order, or the length// parameter is zero.// Greater than zero – The substring in strA follows the substring in strB in the// sort order.//// 异常:// T:System.ArgumentOutOfRangeException:// indexA is greater than strA.System.String.Length. -or- indexB is greater than// strB.System.String.Length. -or- indexA, indexB, or length is negative. -or- Either// indexA or indexB is null, and length is greater than zero.//// T:System.ArgumentException:// comparisonType is not a System.StringComparison value.public static int Compare(String? strA, int indexA, String? strB, int indexB, int length, StringComparison comparisonType);//// 摘要:// Compares substrings of two specified System.String objects using the specified// comparison options and culture-specific information to influence the comparison,// and returns an integer that indicates the relationship of the two substrings// to each other in the sort order.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The starting position of the substring within strA.//// strB:// The second string to use in the comparison.//// indexB:// The starting position of the substring within strB.//// length:// The maximum number of characters in the substrings to compare.//// culture:// An object that supplies culture-specific comparison information. If culture is// null, the current culture is used.//// options:// Options to use when performing the comparison (such as ignoring case or symbols).//// 返回结果:// An integer that indicates the lexical relationship between the two substrings,// as shown in the following table.// Value – Condition// Less than zero – The substring in strA precedes the substring in strB in the// sort order.// Zero – The substrings occur in the same position in the sort order, or length// is zero.// Greater than zero – The substring in strA follows the substring in strB in the// sort order.//// 异常:// T:System.ArgumentException:// options is not a System.Globalization.CompareOptions value.//// T:System.ArgumentOutOfRangeException:// indexA is greater than strA.Length. -or- indexB is greater than strB.Length.// -or- indexA, indexB, or length is negative. -or- Either strA or strB is null,// and length is greater than zero.public static int Compare(String? strA, int indexA, String? strB, int indexB, int length, CultureInfo? culture, CompareOptions options);//// 摘要:// Compares substrings of two specified System.String objects, ignoring or honoring// their case and using culture-specific information to influence the comparison,// and returns an integer that indicates their relative position in the sort order.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The position of the substring within strA.//// strB:// The second string to use in the comparison.//// indexB:// The position of the substring within strB.//// length:// The maximum number of characters in the substrings to compare.//// ignoreCase:// true to ignore case during the comparison; otherwise, false.//// culture:// An object that supplies culture-specific comparison information. If culture is// null, the current culture is used.//// 返回结果:// An integer that indicates the lexical relationship between the two comparands.// Value – Condition// Less than zero – The substring in strA precedes the substring in strB in the// sort order.// Zero – The substrings occur in the same position in the sort order, or length// is zero.// Greater than zero – The substring in strA follows the substring in strB in the// sort order.//// 异常:// T:System.ArgumentOutOfRangeException:// indexA is greater than strA.System.String.Length. -or- indexB is greater than// strB.System.String.Length. -or- indexA, indexB, or length is negative. -or- Either// strA or strB is null, and length is greater than zero.public static int Compare(String? strA, int indexA, String? strB, int indexB, int length, bool ignoreCase, CultureInfo? culture);//// 摘要:// Compares two specified System.String objects and returns an integer that indicates// their relative position in the sort order.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero –strA precedes strB in the sort order.// Zero –strA occurs in the same position as strB in the sort order.// Greater than zero –strA follows strB in the sort order.public static int Compare(String? strA, String? strB);//// 摘要:// Compares substrings of two specified System.String objects by evaluating the// numeric values of the corresponding System.Char objects in each substring.//// 参数:// strA:// The first string to use in the comparison.//// indexA:// The starting index of the substring in strA.//// strB:// The second string to use in the comparison.//// indexB:// The starting index of the substring in strB.//// length:// The maximum number of characters in the substrings to compare.//// 返回结果:// A 32-bit signed integer that indicates the lexical relationship between the two// comparands.// Value – Condition// Less than zero – The substring in strA is less than the substring in strB.// Zero – The substrings are equal, or length is zero.// Greater than zero – The substring in strA is greater than the substring in strB.//// 异常:// T:System.ArgumentOutOfRangeException:// strA is not null and indexA is greater than strA.System.String.Length. -or- strB// is not null and indexB is greater than strB.System.String.Length. -or- indexA,// indexB, or length is negative.public static int CompareOrdinal(String? strA, int indexA, String? strB, int indexB, int length);//// 摘要:// Compares two specified System.String objects by evaluating the numeric values// of the corresponding System.Char objects in each string.//// 参数:// strA:// The first string to compare.//// strB:// The second string to compare.//// 返回结果:// An integer that indicates the lexical relationship between the two comparands.// Value – Condition// Less than zero –strA is less than strB.// Zero –strA and strB are equal.// Greater than zero –strA is greater than strB.public static int CompareOrdinal(String? strA, String? strB);
后面两个方法,是前面两个方法的快捷调用形式。
所有的顺序比较都放回正数、负数或者零。者取决于第一个值是在第二个值之后,之前还是相同的位置:
Console.WriteLine("Boston".CompareTo("Austin"));//1
Console.WriteLine("Boston".CompareTo("Boston"));//0
Console.WriteLine("Boston".CompareTo("Chicago"));//-1
Console.WriteLine("Boston0".CompareTo("Boston1"));//-1
Console.WriteLine("Boston2".CompareTo("Boston1"));//1
Console.WriteLine("ǖ".CompareTo("ǖ"));//0
Console.WriteLine("foo".CompareTo("FOO"));//-1
以下语句使用当前文化进行不区分大小写的比较:
Console.WriteLine(string.Compare("foo", "FOO", true));//0
6.1.4 StringBuilder
StringBuilder类(System.Text命名空间)表示一个可变(可编辑)的字符串。
StringBuilder可以直接进行子字符串的Append、Insert、Remove和Replace而不需要替换整个StringBuilder。
StringBuilder的构造器可以选择接受一个初始字符串值,及其内部容量的初始值(默认为16个字符)。如果需要更大的容量,则StringBuilder会自动(以较小的性能代价)调整它的内部结构,以至其最大的容量(默认为int.MaxValue)。
StringBulider一般通过反复调用Append来构建较长的字符串,这比反复连接字符串类型对象要高效得多。
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 50; i++)
{sb.Append(i + ",");
}
Console.WriteLine(sb.ToString());
输出结果:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
在上述例子中,表达式i+","表示我们仍然在反复连接字符串。但是由于我们使用的字符串很小,因此这个操作的性能开销非常少,并不会随着循环迭代而增长。然而,为了实现最好的性能,我们可以将循环体修改为:
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 50; i++)
{sb.Append(i);sb.Append(",");
}
Console.WriteLine(sb.ToString());
AppendLine执行Append操作,随后添加一个换行序列(在Windows下为”\r\n“)。而AppendFormat则接受一个组合格式字符串,这和String.Format是类似的。除了Insert、Remove和Replace方法(Replace方法和字符串的Replace方法类似),StringBuilder还定义了Length属性和一个可写的索引器,以获得/设置每一个字符。
如果要清除StringBuilder的内容,可以创建一个新的StringBuilder或者将其Length设置为零。
将StringBuilder的Length属性设置为0并不会减小其内部容量。因此,如果之前StringBuilder已经包含了一百万个字符,则它在Length设置为0后仍然占用2MB的内存。因此,如果希望释放这些内存,则必须新建一个StringBuilder,然后将旧的对象清除出作用域(从而可以被垃圾回收)。
6.1.5 文本编码和Unicode
字符集是一种字符配置,每一对配置包含了数字码或者代码点(code point)。常用的字符集由两种:Unicode和ASCII。Unicode具有约一百万个字符的地址空间,目前已经分配的大约有100000个。Unicode包括世界上使用最广泛的语言、一些历史语言及特殊符号。ASCII字符集只是Unicode字符集的前128个字符。它包括US风格键盘上的大多数字符。ASCII比Unicode出现早30年,有时仍以其简单性和高效性而得到应用,它的每一个字符是用一个字节表示的。
.NET类型系统的设计使用的是Unicode字符集,但是它隐含支持ASCII字符集,因为ASCII字符集是Unicode的子集。
文本编码(text encoding)是将字符从数字代码点映射到二进制表示的方法。在.NET中,文本编码主要用预处理文本文件和流。当将一个文本文件读取到字符串时,文本编码器(text encoder)会将文件数据从二进制转换为char和string类型使用的内部Unicode表示。文本编码能够限制哪些字符被识别并影响存储效率。
.NET的文本编码分为两类:
一类是将Unicode字符映射到其他字符集
一类是使用标准的Unicode编码模式
第一类包含遗留的编码方式,例如IBM的EBCDIC,以及包含前128个区域扩展字符的8位字符集(这种将字符集字以代码页进行区分的方法,在Unicode之前就已经普遍存在了)。ASCII编码也属于这一类:它将对前128个字符编码,然后去掉其他字符。这个分类也包含GB18030(这种编码方式并非遗留编码方式),这种编码是从2000年以后,在中国开发或者在中国销售的应用程序的强制编码标准。
第二类是UTF-8、UTF-16、UTF-32。每一种编码方式在空间的使用效率都有所差别。UTF-8对于大多数文本而言是最具空间效率的:它使用1~4个字节来表示每一个字符。前128个字符只需要一个字节,这样它就可以兼容ASCII.UTF-8是最普遍的文本文件和流编码方式(特别是在Internet上),并且是.NET中默认的流的I/O编码方式(事实上,它几乎是所有语言隐含的默认编码方式)。
UTF-16使用一个或者两个16位字来表示一个字符,它是.NET内部表示字符和字符串的方式。有一些程序也使用UTF-16来写入文件内容。
UTF-32是空间效率最低的:每一个代码点直接对应一个32位数,所以每一个字符都会占用4个字节。因此,UTF-32很少使用。然而由于每一个字符都有同样的字节数,因此它可以简化随机访问操作。
6.1.5.1 获取一个Encoding对象
System.Text中的Encoding类是封装文本编码的基类型。它有一些子类,封装了具有相同特性的编码方式。实例化一个正确配置的编码类的最简单方法是使用标准的IANA(互联网数字分配机构吗Internet Assigned Numbers Authority)字符集名称调用Encoding.GetEncoding方法。
Encoding utf8 = Encoding.GetEncoding("utf-8");
Encoding chinese = Encoding.GetEncoding("GB18030");
最常用的编码也可以通过调用Encoding类的特定静态属性获得:
编码名称 | Encoding类的静态属性 |
---|---|
UTF-8 | Encoding.UTF8 |
UTF-16 | Encoding.Unicode(注意不是UTF-16) |
UTF-32 | Encoding.UTF-32 |
ASCII | Encoding.ASCII |
静态方法GetEncodings返回所有支持的编码方式清单及其标准的LANA名称:
foreach(EncodingInfo info in Encoding.GetEncodings())Console.WriteLine(info.Name);
获取编码方式的另一个方法是直接实例化Encoding类。这样做可以通过构造器参数来设置各种选项,包括:
1.在解码,如果遇到一个无效字节系列,是否抛出异常。默认为false.
2.对UTF-16/UTF-32进行编码/解码时是否使用最高有效字节优先(大字节存储顺序)或最低有效字节优先(小字节存储顺序,little endian)。默认值为小字节存储顺序。这也是Windows操作系统的标准。
3.是否使用字节顺序标记(表示字节顺序的前缀)。
6.1.5.2 文件与流I/O编码
Encoding对象最常见的应用是控制文件或流的文本读写操作,例如,下面的代码将“Testing…"以UTF-16的编码方式写入文件data.txt中:
System.IO.File.WriteAllText("data.txt", "testing", Encoding.Unicode);
如果省略最后一个参数,则WriteAllText会使用最普遍的UTF-8编码方式。
UTF-8是所有文件和流I/O的默认文本编码方式。
6.1.5.3 编码为字节数组
Encoding对象可以将文本转换为字节数组,反之亦然。GetBytes方法用指定的编码方式将string转换为byte[];而GetString则将byte[]转换为string:
System.IO.File.WriteAllText("data.txt", "testing"
相关文章:
C#核心笔记——(六)框架基础
我们在编程时所需的许多核心功能并不是由C#语言提供的,而是由.NET Framework中的类型提供的。本节我们将介绍Framework在基础编程任务(例如虚的等值比较、顺序比较以及类型转换)中的作用。我们还会介绍Framework中的基本类型,例如String、DateTime和Enum. 本章中的绝大部分…...
C# 点击导入,将需要的参数传递到弹窗的页面
点击导入按钮,获取本页面的datagridview标题的结构,并传递到导入界面。 新增一个datatable用于存储datagridview的caption和name,这里用的是devexpress组件中的gridview。 DataTable dt new DataTable(); DataColumn CAPTION …...
java面向对象编程【基础篇】之基础概念
目录 🚀前言🤔面向过程VS面向对象💯面向过程编程(POP)💯面向对象编程(OOP)💯两者对比 🌟三大特性💯封装性💯继承性💯多态性…...
Oceanbase单机版上手示例
本月初Oceanbase单机版发布,作为一个以分布式起家的数据库,原来一个集群动辄小十台机器,多着十几台几十台甚至更多,Oceanbase单机版的发布确实大大降低了硬件部署的门槛。 1.下载安装介质 https://www.oceanbase.com/softwarece…...
深度学习基础--CNN经典网络之InceptionV3详解与复现(pytorch)
🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 前言 InceptionV3是InceptionV1的升级版,虽然加大了计算量,但是当时效果是比VGG效果要好的。本次任务是探究InceptionV3结构并进行复…...
VOIP通信中的错误码
cancle报文 Reason: SIP;cause200;text"Call completed elsewhere" Reason: Q.850;cause26表示取消的原因是呼叫在其他地方已经完成表示Q.850标准中的原因码26,通常对应于“呼叫被取消”(Call Cancelled)487 Request Terminated Re…...
C++ STL编程-vector概念、对象创建
vector 概念:是常见的一种容器,被称为“柔性数组”。 在vector中,front()是数组中的第一个元素,back()是数组的最后一个元素。begin()是是指向第一个元素,end()是指向back()的后一个元素 vector的对象创建࿰…...
easyexcel使用模板填充excel坑点总结
1.单层map设置值是{属性},那使用两层map进行设置值,是不是可以使用{属性.属性},以为取出map里字段只用{属性}就可以设置值,那再加个.就可以从里边map取出对应属性,没有两层map写法 填充得到的文件打开报错 was empty (…...
C#学习第16天:聊聊反射
什么是反射? 定义:反射是一种机制,允许程序在运行时获取关于自身的信息,并且可以动态调用方法、访问属性或创建实例。用途:常用于框架设计、工具开发、序列化、代码分析和测试等场景 反射的核心概念 1. 获取类型信息…...
【Unity】使用Cinemachine+CharacterController实现第三人称视角下的角色视角、移动和跳跃控制
1.初始配置 安装Cinemachine插件给角色添加CharacterConroller创建Cinemachine-->Free Look Camera在Free Look Camera中调整参数,Y Axis勾选Inver,X Axis取消勾选InverFree Look Camera要看向角色 跟随角色(自行设置,我就不…...
如何通俗的理解transformer架构编码器和解码器干的活
我们可以用生活中的比喻来理解Transformer的编码器和解码器,以及解码器中两种注意力的作用: 一、编码器(Encoder):理解信息的「分析师团队」 想象你要翻译一句话,比如把中文“今天天气很好”翻译成英文。编…...
React 受控表单绑定基础
React 中最常见的几个需求是: 渲染一组列表绑定点击事件表单数据与组件状态之间的绑定 受控表单绑定是理解表单交互的关键之一。 📍什么是受控组件? 在 React 中,所谓“受控组件”,指的是表单元素(如 &l…...
UMG:ListView
1.创建WEB_ListView,添加Border和ListView。 2.创建Object,命名为Item(数据载体,可以是其他类型)。新增变量name。 3.创建User Widget,命名为Entry(循环使用的UI载体).添加Border和Text。 4.设置Entry继承UserObjectListEntry接口。 5.Entry中对象生成时…...
实验五 内存管理实验
实验五 内存管理实验 一、实验目的 1、了解操作系统动态分区存储管理过程和方法。 2、掌握动态分区存储管理的主要数据结构--空闲表区。 3、加深理解动态分区存储管理中内存的分配和回收。 4、掌握空闲区表中空闲区3种不同放置策略的基本思想和实现过程。 5、通过模拟程…...
初识 Firebase 与 FPM
Firebase 是什么 ? Firebase 是 Google 旗下面向 iOS、Android、Web 与多端框架(Flutter、Unity 等)的应用开发平台,提供从「构建 → 发布与运维 → 增长」全生命周期的一站式后端即服务(BaaS)。它把实时数据库、托管…...
探索C++中的数据结构:栈(Stack)的奥秘
引言 栈是计算机科学中最基础且重要的数据结构之一,它像一摞盘子一样遵循"后进先出"(LIFO)的原则。无论是函数调用、表达式求值,还是浏览器前进后退功能,栈都扮演着关键角色。本文将深入解析栈的C实现及其应…...
vue3 nprogress 使用
nprogress 介绍与作用 1.nprogress 是一个轻量级的进度条组件,主要用于在页面加载或路由切换时显示一个进度条,提升用户体验。它的原理是通过在页面顶部创建一个 div,并使用 fixed 定位来实现进度条的效果 2.在 Vite Vue 3 项目中…...
MCP(Model Context Protocol 模型上下文协议)科普
MCP(Model Context Protocol,模型上下文协议)是由人工智能公司 Anthropic 于 2024年11月 推出的开放标准协议,旨在为大型语言模型(LLM)与外部数据源、工具及服务提供标准化连接,从而提升AI在实际…...
韩媒专访CertiK创始人顾荣辉:黑客攻击激增300%,安全优先的破局之路
4月17日,韩国知名科技媒体《韩国IT时报》(Korea IT Times)发布了对CertiK联合创始人兼CEO顾荣辉教授的专访。双方围绕CertiK一季度《HACK3D》安全报告,就黑客攻击手法的迭代和安全防御技术的创新路径等,展开深度对话。 顾荣辉认为࿰…...
华为openEuler操作系统全解析:起源、特性与生态对比
华为openEuler操作系统全解析:起源、特性与生态对比 一、起源与发展历程 openEuler(欧拉操作系统)是华为于2019年开源的Linux发行版,其前身为华为内部研发的服务器操作系统EulerOS。EulerOS自2010年起逐步发展,支持华…...
从零实现Git安装、使用
一、git安装 Git官方下载 1.下载exe程序 2.双击安装,一直点击next,默认安装 安装完成后,在任意文件夹右键,出现下图所示,即为安装成功。 3.【Git Bash Here】调出命令窗口,设置用户名和 email 地址。 gi…...
leetcode刷题日记——单词规律
[ 题目描述 ]: [ 思路 ]: 题目要求判断字符串 s 中的单词是否按照 pattern 这种模式排列具体思路和 205. 同构字符串基本一致,可以通过 hash 存储来实现思路二,通过字符串反推 pattern,如果一致,则遵循相…...
Ubuntu 修改语言报错Failed to download repository information
1.进入文件(ps:vim可能出现无法修改sources.list文件的问题) sudo gedit /etc/apt/sources.list2.修改(我是直接增添以下内容在其原始源前面,没有删原始内容)文件并保存,这里会替换原文件 deb http://mirrors.aliyun.com/ubuntu/ focal mai…...
烹饪与餐饮管理实训室数字课程开发方案
烹饪与餐饮管理专业需要具有餐饮产品设计、研发的能力; 具有饮食美学、科学配餐与高端宴席设计的能力; 具有餐饮企业、中央厨房运营管理的能力; 具有餐饮信息化系统应用、数字化运营的能力,这些能力的培养,需要烹饪与餐…...
关于模拟噪声分析的11个误区
目录 1. 降低电路中的电阻值总是能改善噪声性能 2. 所有噪声源的噪声频谱密度可以相加,带宽可以在最后计算时加以考虑 3. 手工计算时必须包括每一个噪声源 4. 应挑选噪声为ADC 1/10的ADC驱动器 5. 直流耦合电路中必须始终考虑1/f噪声 6. 因为1/f噪声随着频率降…...
基于 S2SH 架构的企业车辆管理系统:设计、实现与应用
在企业运营中,车辆管理是一项重要工作。随着企业规模的扩大,车辆数量增多,传统管理方式效率低下,难以满足企业需求。本文介绍的基于 S2SH 的企业车辆管理系统,借助现代化计算机技术,实现车辆、驾驶员和出车…...
51单片机实验七:EEPROM AT24C02 与单片机的通信实例
目录 一、实验环境与实验器材 二、实验内容及实验步骤 三、proteus复位电路 1.改电阻的阻值(方法一) 2.改电阻的属性(方法2) 一、实验环境与实验器材 环境:Keli,STC-ISP烧写软件,Proteus. …...
【TeamFlow】 1 TeamFlow 去中心化生产协同系统架构
总体架构设计 采用四层混合架构,结合分层设计与去中心化网络: #mermaid-svg-qBgw9wMd8Gi0gOci {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-qBgw9wMd8Gi0gOci .error-icon{fill:#552222;}…...
第 8 期:条件生成 DDPM:让模型“听话”地画图!
本期关键词:Conditional DDPM、Class Embedding、Label Control、CIFAR-10 条件生成 什么是条件生成(Conditional Generation)? 在标准的 DDPM 中,我们只是“随机生成”图像。 如果我想让模型生成「小狗」怎么办&…...
树莓派超全系列教程文档--(32)config.txt常用音频配置
config.txt常用音频配置 板载模拟音频(3.5mm耳机插孔)audio_pwm_modedisable_audio_ditherenable_audio_ditherpwm_sample_bits HDMI音频 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 板载模拟音频(3.5mm耳机…...
Perf学习
重要的能解决的问题是这些: perf_events is an event-oriented observability tool, which can help you solve advanced performance and troubleshooting functions. Questions that can be answered include: Why is the kernel on-CPU so much? What code-pa…...
量子神经网络编译器开发指南:从理论突破到产业落地全景解析
本文深度剖析IBM Qiskit 5.0量子经典混合编译器的技术架构,详解如何基于含噪量子处理器实现MNIST手写数字分类任务(准确率达89%)。结合本源量子云、百度量子等国内平台免费配额政策,系统性阐述量子神经网络开发的技术路线与资源获…...
守护者进程小练习
守护者进程含义 定义:守护进程(Daemon)是运行在后台的特殊进程,独立于控制终端,周期性执行任务或等待事件触发。它通常以 root 权限运行,名称常以 d 结尾(如 sshd, crond)。 特性&a…...
研究生面试常见问题
研究生面试是考研复试的重要环节,面试表现直接关系到录取结果。以下从面试流程、常见问题分类及回答技巧等方面为您整理了相关内容,帮助您更好地准备面试。 一、研究生面试的基本流程 自我介绍:通常需要准备1分钟左右的中文或英文自我介绍&a…...
极狐GitLab 登录限制如何设置?
极狐GitLab 是 GitLab 在中国的发行版,关于中文参考文档和资料有: 极狐GitLab 中文文档极狐GitLab 中文论坛极狐GitLab 官网 登录限制 (BASIC SELF) 您可以使用登录限制自定义 Web 界面以及基于 HTTP(S) 的 Git 的身份验证限制。 设置 要访问登录限…...
AI驱动商业变革:零售行业的智能化跃迁
引言:AI技术迈入黄金时代 2024年成为生成式AI(Gen AI)全面落地的关键年。据麦肯锡《技术趋势展望》报告,生成式AI相关投资同比增长7倍,其经济价值预计达2.6-4.4万亿美元[1]。在零售领域,该技…...
初始图像学(6)
Camera类 我们之前学了很多的图形学知识和相关的程序,现在我们停下脚步,来好好整理一下我们学习的内容,我们将之前的视口代码和渲染代码合并到一个新的单类camera.h,这个类主要负责两项任务: 构建并发射光线到世界中 …...
【React】通过 fetch 发起请求,设置 proxy 处理跨域
fetch 基本使用跨域处理 fetch 基本使用 在node使用原生ajax发请求:XMLHttpRequest()1.获取xhr对象 2.注册回调函数 3.设置参数,请求头 4.发起连接原生ajax没有带异步处理 promise;原生ajax封装一下,以便重复调用jQuery&#…...
好数对的数目
题目描述 给你一个整数数组 nums。 如果一组数字 (i, j) 满足 nums[i] nums[j] 且 i < j,就可以认为这是一组 好数对。 返回 好数对 的数目。 示例 示例 1: 输入:nums [1,2,3,1,1,3] 输出:4 解释: 有 4 组好…...
Animated Raindrop Ripples In HLSL
这节课是利用材质做雨滴i效果 首先是创建一个圆环,实际上他就是为了创建一个圆,但是是空心的,可以看之前我的做法,这里以他的为准 创建圆环 就是当uv的点在max_radius和min_radius之间的时候绘制。 他这里写了ringThickness&a…...
Linux学习——守护进程编程
一、守护进程含义及实现过程 1、含义 守护进程(Daemon Process) 是操作系统中一种在后台长期运行的特殊进程,通常不与用户直接交互。它独立于控制终端,用于执行周期性任务或系统服务(如日志管理、网络服务等ÿ…...
【C++】 —— 笔试刷题day_19
一、小易的升级之路 题目解析 小易现在要打游戏,现在游戏角色的初始能力值为a,我们会遇到n个怪,这些怪物的防御值为b1、b2、b3...,如果我们的能力值要高于或者等于怪物的防御值,那我们的能力值就会加bi;如…...
gitee提交大文件夹
# 安装 Git LFS(如果未安装) git lfs install# 跟踪整个大文件夹(或特定大文件类型) git lfs track "big_folder/**" # 替换为你的文件夹名# 提交并推送 git add .gitattributes big_folder/ git commit -m "add …...
纯CSS实现自动滚动到底部
<!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>自动滚动到底部</title><style>*…...
WInform当今技术特性分析
Windows Forms (WinForms) 技术特性分析 引言 Windows Forms (WinForms) 作为微软最早推出的基于.NET的图形用户界面开发框架,已经存在了20多年。在如今充满了各种现代UI框架的软件开发生态系统中,WinForms仍然保持着其独特的地位。本文将深入分析WinF…...
6.5 GitHub监控系统实战:双通道采集+动态调度打造高效运维体系
GitHub Sentinel Agent 定期更新功能设计与实现 关键词:GitHub API 集成、定时任务调度、Python 爬虫开发、SMTP 邮件通知、系统稳定性保障 1. GitHub 项目数据获取功能 1.1 双通道数据采集架构设计 #mermaid-svg-ZHJIMXcMAyDHVhmV {font-family:"trebuchet ms",v…...
自动驾驶安全模型研究
自动驾驶安全模型研究 自动驾驶安全模型研究 自动驾驶安全模型研究1.自动驾驶安全模型概述2. 自动驾驶安全模型应用3. 自动驾驶安全模型介绍3.1 Last Point to Steer3.2 Safety Zone3.3 RSS (Responsibility-Sensitive Safety)3.4 SFF (Safety Force Field)3.5 FSM (Fuzzy Safe…...
4090租用,各云GPU平台价格对比清单及建议
根据各平台的价格和型号配置,以下是通过DeepSeek-R1进行分析后,给出的建议。 一、按显存需求推荐 1.24G显存需求(适合常规AI训练/推理、中小模型) 性价比首选:智星云(1.35元/小时) ࿰…...
Linux:简单指令(二)
文章目录 man ~~echocatcp指令which ~~mvless时间相关的指令find 要么对内容要么对属性操作 决定路径开始定位文件,也可以相对路径 家目录/ man ~~ 1查询具体命令 我们可以man man 可以看man 的描述 我们可以man 数字 ~~ 可以从上到下查询 2查询仿命令 3查询具体接口…...
代码随想录算法训练营day7(字符串)
华子目录 反转字符串中的单词思路 右旋字符串思路 反转字符串中的单词 https://leetcode.cn/problems/reverse-words-in-a-string/description/ 思路 先将字符串s按照空格切分为列表s_list(使用s.split())再进行反转操作再将列表拼接为字符串ÿ…...