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

Example Analysis of regular expression and carriage return newline character in C #

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

I would like to share with you the example analysis of regular expressions and carriage return newline characters in C#. I hope you will gain something after reading this article. Let's discuss it together.

In C #, when reading the contents of a text file, there are often many carriage return newline characters ("\ r\ n"), which are generally invisible but real. At this point, the use of regular expressions for matching, you need to consider its existence. There is such a problem today:

The contents of the text file are as follows:

DT 20180101000000WT-1.1SL 31.4WL 203DT 20180101000000AT-4.1BP 1023.7HU 26RN 99999.9WS 1.92.094 3.479 2111 4.683 2103

Using the regular expression: WT\ s + (?. +) $, the result is no match. The reason is that the read text contains a lot of carriage return newline characters "\ r\ n". For example, in the line of WT-1.1, the substance is

"WT-1.1\ r\ n", when the line trailing character "$" has no effect. It should be said that reading the contents of the file directly and using regular expression matching will not work.

Change the regular expression to:

WT\ s + (?. +)\ r\ nAfter reading this article, I believe you have some understanding of "sample analysis of regular expressions and carriage return newline characters in C#". If you want to know more about it, welcome to follow the industry information channel. Thank you for reading!

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

Internet Technology

Wechat

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

12
Report