Visual Studio 报告“未找到以下指定文本”但仅在进行替换时?

发布于 2024-11-04 10:52:27 字数 960 浏览 0 评论 0原文

我打算用 this 来替换

:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:b

这个

:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:bmyclass.dateclass.activite\(Request.ServerVariables\[\"LOGON_USER\"\].Split\('\\\\'\)\[1\], Request.Url.AbsoluteUri\);\n:b:b:b:b:b:b:b:b:b:b:b:b

:我确实使用 FIND 找到了第一个表达式,但它说当我使用 REPLACE 时找不到它。

这是我的代码示例

        //Affichage de la page 
    void Page_Load()
    {
        myclass.dateclass.activite(Request.ServerVariables["LOGON_USER"].Split('\\')[1], Request.Url.AbsoluteUri);
        java.Text = "<script language=\"JavaScript1.2\" type=\"text/javascript\">var sess = \"" + Session["username"] + "\";var user = \"" + Request.ServerVariables["LOGON_USER"].Replace("\\", "\\\\") + "\";</script>";
        Session.LCID = 3084; //Utilise des dates en format AAAA-MM-JJ

I am tying to replace this:

:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:b

by this

:b:b:b:b:b:b:b:bvoid Page_Load\(\)\n:b:b:b:b:b:b:b:b\{\n:b:b:b:b:b:b:b:b:b:b:b:bmyclass.dateclass.activite\(Request.ServerVariables\[\"LOGON_USER\"\].Split\('\\\\'\)\[1\], Request.Url.AbsoluteUri\);\n:b:b:b:b:b:b:b:b:b:b:b:b

. I do find the first expression using FIND, but it says that it can't find it when I use REPLACE.

Here is a sample of my code

        //Affichage de la page 
    void Page_Load()
    {
        myclass.dateclass.activite(Request.ServerVariables["LOGON_USER"].Split('\\')[1], Request.Url.AbsoluteUri);
        java.Text = "<script language=\"JavaScript1.2\" type=\"text/javascript\">var sess = \"" + Session["username"] + "\";var user = \"" + Request.ServerVariables["LOGON_USER"].Replace("\\", "\\\\") + "\";</script>";
        Session.LCID = 3084; //Utilise des dates en format AAAA-MM-JJ

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨敛清荷 2024-11-11 10:52:27

在替换字符串中使用圆括号或引号时,不需要对其进行转义,也不会识别某些字符代码,包括 :b

首先,将您的查找字符串更改为此(外部的大括号是 VS 自己定义捕获组的特殊方式):

{void Page_Load.+\n[^\{]+\{}

然后,将您的替换字符串更改为此(请注意要引用的 \1替换中的捕获组)。

\1\nmyclass.dateclass.activite(Request.ServerVariables\["LOGON_USER"\].Split('\\\\')\[1\], Request.Url.AbsoluteUri);\n

Visual Studio 给您返回的“未找到以下指定文本”错误实际上是错误的 - 这是替换字符串的问题,而不是要查找的字符串的问题。

可能值得下载这样的东西 正则表达式搜索和替换插件 来减轻您的头痛不得不处理 Visual Studio 奇怪的正则表达式语法。

You don't need to escape round brackets or quotes when using them in the replacement string, nor does it recognise certain character codes, including :b.

Firstly, change your find string to this (the curly braces around the outside are VS's own idiosyncratic way of defining a capture group):

{void Page_Load.+\n[^\{]+\{}

Then, change your replacement string to this (note the \1 to refer to the capture group in the replacement).

\1\nmyclass.dateclass.activite(Request.ServerVariables\["LOGON_USER"\].Split('\\\\')\[1\], Request.Url.AbsoluteUri);\n

The "the following specified text was not found" error that Visual Studio gives you back is actually wrong - it's an issue with the replacement string rather than the string to find.

It's probably worth downloading something like this Regex Search and Replace Addin to save you the headache of having to deal with Visual Studio's bizarre regex syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文