Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the operating methods related to .net Framework text processing?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you. Net Framework text processing related operation methods, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

The .net Framework development environment helps us provide a very powerful writing platform.

Convert between numeric values and Char instances:

Transformation: efficiency *. The compiler will directly generate IL instructions to perform the conversion without any method calls.

However, the disadvantage is that the compiler treats the numeric type that is expected to be converted as a primitive type. / / c = (Char) 65

Using Convert types: the System.Convert type provides static methods for checked operations

/ / c=Convert.ToChar (65)

.net Framework text processing uses the Iconvertible interface: the Char type and all numeric types in the .NET Framework class library FCL implement the

Iconvertible interface, which defines a method such as ToChar; but it is not efficient, and the value type is converted into interface boxing problem / / c = ((IConvertible) 65) .ToChar (null)

C # believes that String is a primitive type and cannot use the new operator to create String objects.

String s = "Hi there"

String file= "C:"Windows"

String file=@ "C:" Windows "

The / / @ symbol tells the compiler that the string is a

Literal string with strong readability

The most important property of a String object is its constancy. That is, once a string is created, it is no longer possible to make it longer, shorter, or change any of its characters.

Compilers in .net Framework text processing typically place text constant strings in the metadata of a managed module and then access them at run time using a mechanism called string hosting string interning.

String s = "Hello"

Console.WriteLine (Object.

ReferenceEquals ("Hello", s)

/ / when * methods that refer to strings are compiled by JIT, all text constant strings embedded in the source code are always added to the hash table within CLR

Dynamically create strings at run time:

String S1 = "Hello"

Sting S2 = "Hel"

String s3rooms2 + "lo"

Console.WriteLine (Object.

ReferenceEquals (S1 ~ S3))

/ / return false, because the dynamically created string is not added to the hash table within CLR

If all string comparisons in an application are simply comparing references rather than character sets, and there is a .net Framework text processing method that can turn dynamic strings with the same character set into a string object in the managed heap, this will greatly improve system performance.

S3=String.Intern (S3); / / returns a reference to an existing string object. If it is not found, the string will be added to the hash table within CLR.

S3=String.IsInterned (S3); / / cannot be found. Return null

The string resident technique is used only when we need to compare the same string multiple times in the application.

String pool technology string pooling: write multiple strings only once to the metadata of the managed module

Because the string type represents a constant string, FCL provides another type of System.Text.StringBuilder, which allows us to create String objects by performing dynamic operations on strings and characters.

A common no-parameter ToString method is defined in System.Object, and we can get a string representation of that instance by calling ToString on any type of instance.

If we need our own type to provide format and language and culture choices for the caller, we should implement the System.Iformattable interface:

Public interface Iformattable {

String ToString (String

Format,IformatProvider

FormatProvider)

}

Format multiple objects as a string:

String s=String.Format

("On {0vir D}, {1} is {2v E}"

Years old. ", DateTime.Now

"Wallace", 35)

Console.WriteLine (s)

/ / String's static method Format accepts a formatted string and uses numbers in curly braces to identify replaceable parameters for the format string.

StringBuilder's AppendFormat method is that we can format objects in any way we want.

Any type in .net Framework text processing that can parse a string provides a common static method called Parse, which accepts a String and returns an instance of the type.

The above is the operation of .net Framework text processing. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report