In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is mainly about "how to use StringBuilder and string of C#". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use StringBuilder and string of C#"!
Whether 1.string is a reference type or a value type
MSDN officially says that string is a reference type.
Reference type: reference allocates stack memory, and the data of the reference type itself is stored in the heap
Value type: created in function, stack memory; member variable heap type in class
From the analysis of c underlying memory, string is essentially an char* array.
Char* does not open the heap, and direct "" assignment is stored in the constant memory area.
The constant memory area is released uniformly by the system at the end of the program.
String assignment, like char*, is directly stored in constant memory.
Therefore, a string re-assignment is not to modify the reference point, but to re-point to a new string in constant memory, which is tantamount to recreating the instance with poor performance.
2.StringBuilder
StringBuilder is equivalent to char* a = new char [lenth]
Opened a piece of heap memory to store string data
StringBuilder can specify the memory size when creating an object
StringBuilder mStringBuilder = new StringBuilder ("LittlePreilla", 30)
When memory runs out, StringBuilder automatically doubles memory
MStringBuilder.Capacity = 10; / / set memory mStringBuilder.EnsureCapacity (10); / / check memory. If it is larger than 10, it will remain unchanged. If it is less than 10, 103.StringBuilder will use 1) splicing mStringBuilder.Append ("aaa"); mStringBuilder.AppendFormat ("aaa {0103.StringBuilder D}", 1012) Character description sample output C currency string.Format ("{0:C3}", 2) $2.000D decimal string.Format ("{0:D3}", 2) 002E Scientific count string.Format ("{00:D3 e}", 1.2) 1.20E+001G regular string.Format ("{00:D3 G}", 2) 2N digits separated by semicolons string.Format ("{0:D3}", 250000) 250000.00X hexadecimal string.Format ("{0:X000}", 12) C
String.Format ("{ddd 000.000}", 012.2002) insert mStringBuilder.Insert (1, "ddd"); / / index position 3 below) remove mStringBuilder.Remove (1); / / index start from the table below, remove bits 4) replace mStringBuilder.Replace ("aaa", "bbb"); I personally prefer regular expressions for formatting output, which is also very convenient Int a = 10 * * string str = $"aaa {10} bbbb"; / / the result is aaa10bbbb so far. I believe you have a better understanding of "how to use StringBuilder and string of C#". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.