【问题标题】:Condition Search and replace C#条件搜索和替换 C#
【发布时间】:2012-06-12 08:02:57
【问题描述】:

您好,感谢您的关注。

编辑:我不是程序员,我几乎不知道 C# 或任何其他语言,所以,抱歉这个问题,我一直在寻找解决方案,但没有任何效果。无论如何,谢谢你否决了我的问题。

言归正传,我得到了这个代码:

using System;
using VisualWebRipper.Internal.SimpleHtmlParser;
using VisualWebRipper;
public class Script
{

    public static string TransformContent(WrContentTransformationArguments args)
    {
        try
        {
            //Place your transformation code here.
            //This example just returns the input data

            return args.Content;
        }
        catch(Exception exp)
        {
            //Place error handling here
            args.WriteDebug("Custom script error: " + exp.Message);
            return "Custom script error";
        }
    }
}

我需要用 C# 做一个条件,让我在 *args.Content(包含变量字符串)中找到字符串 "No se exige",并且如果 Find 匹配,它将字符串值更改为数字 (0) 并返回它。如果不是什么都没有改变。

所以,我只需要搜索一个字符串并将其替换为一个数字,如果它与字符串“No se exige”匹配。

非常感谢您努力阅读我的英语,希望您能帮助我:)

【问题讨论】:

  • 到目前为止您尝试过什么?不要指望这个网站不费吹灰之力就为你做功课......
  • 几个例子会使描述清晰千倍
  • whathaveyoutried.com - 为了我们和我们的兄弟们,请阅读它。
  • 我很抱歉,但我不是程序员,所以我问:(
  • 如果你不是程序员,那你为什么要写代码?

标签: c# search replace conditional-statements


【解决方案1】:

只需使用Replace 方法:

args.Content = args.Content.Replace("No se exige", "0");

【讨论】:

  • 大概他们投了反对票,因为他们希望用户自己尝试一些东西并实际学习一些东西,但你是对的,因为它回答了问题,所以我赞成取消它
猜你喜欢
  • 1970-01-01
  • 2018-07-01
  • 1970-01-01
  • 2020-03-21
  • 2014-01-24
  • 1970-01-01
  • 1970-01-01
  • 2015-08-28
  • 2020-07-20
相关资源
最近更新 更多