正则表达式(C#):用\ r \ n替换\ n(Regex (C#): Replace \n with \r\n)
如何使用C#中的正则表达式将\ n的单独实例替换为\ r \ n(仅LF与CRLF)?
对不起,如果这是一个愚蠢的问题,我是新来的正则表达式。
我知道要使用计划
String.Replace
来做,如:myStr.Replace("\n", "\r\n"); myStr.Replace("\r\r\n", "\r\n");
然而,这是不雅的,并且会破坏文本中的任何“\ r + \ r \ n”(尽管它们不可能存在)。
How can I replace lone instances of \n with \r\n (LF alone with CRLF) using a regular expression in C#?
Sorry if it's a stupid question, I'm new to Regex.
I know to do it using plan
String.Replace
, like:myStr.Replace("\n", "\r\n"); myStr.Replace("\r\r\n", "\r\n");
However, this is inelegant, and would destroy any "\r+\r\n" already in the text (although they are not likely to exist).
原文:https://stackoverflow.com/questions/31053
最满意答案
我们很难描述一个通用的策略来调试“很多错误”,所以我将引导您完成调试组件级错误的过程:
为您所选择的浏览器安装React开发工具扩展:
找到组件
我推荐以下任一路径:
2.A. 从浏览器开发工具中打开“
React tab
,然后键入底部搜索栏以按名称查找组件。2.B. 打开
Elements tab
,选择一些元素,然后切换回React
。 组件层次结构将被展开,直到React组件匹配您在Elements
选择的DOM节点。检查行为不正确的组件的状态和道具。
如果由于某种原因你不喜欢安装浏览器扩展,你可以抛出一个或多个
debugger;
语句来设置将“暂停”应用程序执行的断点,并让您检查这些点的调用堆栈,范围和错误。It's difficult to describe a general strategy to debug "a lot error shown up" so I will walk you through the process for debugging component level errors:
Install the React dev tools extension for your browser of choice:
Find the component
I recommend either of these paths:
2.a. Open
React tab
from your browser dev tools and type in the bottom search bar to lookup components by name.2.b. Open
Elements tab
, select some element, and switch back toReact
. The component hierarchy will be expanded up until the React component matching the DOM node you selected inElements
.Inspect the state and props of the component that is behaving incorrectly.
If for some reason you don't like installing browser extensions, you can throw one or more
debugger;
statements to set breakpoints that will "pause" the execution of your app and let you inspect the call stack, scope, and errors at these points.
相关问答
更多-
我们很难描述一个通用的策略来调试“很多错误”,所以我将引导您完成调试组件级错误的过程: 为您所选择的浏览器安装React开发工具扩展: 铬 火狐 找到组件 我推荐以下任一路径: 2.A. 从浏览器开发工具中打开“ React tab ,然后键入底部搜索栏以按名称查找组件。 2.B. 打开Elements tab ,选择一些元素,然后切换回React 。 组件层次结构将被展开,直到React组件匹配您在Elements选择的DOM节点。 检查行为不正确的组件的状态和道具。 如果由于某种原因你不喜欢安装浏览器扩 ...
-
Chrome不允许您通过XHR加载file:// urls(其他地方如何在浏览器转换中工作)。 你有几个选择: 使用不同的浏览器。 我知道Firefox工程。 启动一个本地的Web服务器(Python附带一个,所以如果你已经安装了这个非常简单 - http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python )。 将脚本放在一个单独的文件中。 这对于像这样简单的东西是可行的,但是您会想要尝试其他选项,因为您的代码变 ...
-
有几个基本原则要牢记,可能有助于您构建一个很好的React应用程序: 您的UI应该是数据的一个功能 在许多“jQuery汤”风格的应用程序中,应用程序的业务逻辑,应用程序的数据和UI交互代码都是混合的。 这使得这些应用程序难以进行调试,特别是难以增长。 像许多现代客户端应用程序框架一样,React实现了一个想法,即UI只是您的数据的表示。 如果您希望您的UI更改,您应该更改一个数据,并允许框架用于更新UI的任何绑定系统。 在React中,每个组件(理想情况下)是传递给组件实例的属性以及组件在内部管理的状态的 ...
-
所以我按照本教程获取导航链接以转到页面的其他部分。 我没有使用this.props.children将组件传递给layout.js文件,而是在单个页面上添加了我想要的每个组件,如下所示: return (