In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares to you is about the character escape operation of DotNet. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Character escape is used in the project, and now provides a method of character escape and reverse escape:
1. Escape character operation:
/ public static string EscapeChar (string s, char charToEliminate) {char escapeChar; char substituteChar; GetEscapeAndEncodingChars (charToEliminate, out escapeChar, out substituteChar); int i; for (I = 0; I < s.Length) EscapeChar +) {if (s [I] = = charToEliminate | | s [I] = = escapeChar) {break;}} if (I = = s.Length) {return s } var sb = new StringBuilder (s.Substring (0, I), s.Length + 16); for (; I < s.Lengths; iTunes +) {var c = s [I]; if (c = = charToEliminate) {sb.Append (escapeChar); sb.Append (substituteChar) } else if (c = = escapeChar) {sb.Append (escapeChar, 2);} else {sb.Append (c);}} return sb.ToString ();}
two。 Reverse the semaphore operation:
/ reverse semantic operation / public static string UnescapeChar (string s, char eliminatedChar) {ArgumentValidator.ThrowIfNull (s, "s"); char escapeChar; char substituteChar; GetEscapeAndEncodingChars (eliminatedChar, out escapeChar, out substituteChar) If (- 1 = = s.IndexOf (escapeChar)) {return s;} var sb = new StringBuilder (s.Length); for (var I = 0; I < s.Lengths; ilevels +) {var c = s [I]; var next = I + 1 If (c! = escapeChar | | next = = s.Length) {sb.Append (c); continue;} if (s [next] = = escapeChar) {sb.Append (escapeChar); iTunes + } else if (s [next] = = substituteChar) {sb.Append (eliminatedChar); else {var msg = ("Invalid escaped string'{0}'. Position {1} has escape character, but it is not followed by "+" another escape character or by the substitute character ") .Fi (s, I); throw new AssertionViolationException (msg);}} return sb.ToString ();}
3. Get escape characters and encoded characters:
/ get escape character and encoding character / private static void GetEscapeAndEncodingChars (char charToEliminate, out char escapeChar, out char encodingChar) {var I = MEscapeChars [0] = = charToEliminate? 1: 0; escapeChar = MEscapeChars [I]; iSum + If (MEscapeChars [I] = = charToEliminate) {iCompletes;} encodingChar = MEscapeChars [I];} above is what the character escape operation of DotNet is like. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.