火车浏览器官方论坛

 找回密码
 立即注册
查看: 18931|回复: 12
打印 上一主题 下一主题

[图文] 使用c#代码操作脚本内部的变量

[复制链接]

14

主题

120

帖子

947

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
947
跳转到指定楼层
楼主
发表于 2014-9-30 11:44:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.1(bate9) 中新增运行C#代码的功能
在新建步骤的时候会自动在代码片段中添加默认的方法,这个方法名不能修改,默认调用的方法
  1. public static void Execute( Dictionary<string, string> stringDic,  Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
  2.         {
  3.          
  4.         }
复制代码
在这个方法中可以对变量的值进行操作 key 是变量名  value 是变量的值
默认引用的程序集
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6. using System.IO;
  7. using System.Data;
  8. using System.Threading;
  9. using System.Net;
  10. using System.Timers;
  11. using System.Web;
  12. using System.Collections;
复制代码
在方法中可以对文本型变量,List变量,计数器变量进行读写操作


1. 修改变量Test的值 为 lll
  1. public static void Execute( Dictionary<string, string> stringDic,  Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
  2.         {
  3.             stringDic["Test"] = "lll";
  4.         }
复制代码
2.判断文本型变量[c]的值为a时清空List变量[a]的值
  1. public static void Execute( Dictionary<string, string> stringDic,  Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
  2.         {
  3.             if (stringDic.ContainsKey("c") == false) return;
  4.             if (stringDic["c"] == "a" && listDic.ContainsKey("a")) listDic["a"] = new List<string>();
  5.         }
复制代码




回复

使用道具 举报

14

主题

120

帖子

947

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
947
推荐
 楼主| 发表于 2014-12-17 09:38:52 | 只看该作者
lankii 发表于 2014-12-17 03:42
请版主完善教程,是不是支持所有代码还是仅仅是对存在变量的操作》

动态生成报错

您的代码写错了!
  1. List<string> yyy=new List<string>();
  2.           yyy.Add("kkk");
  3.           listDic.Add("C#",yyy);
复制代码



回复 支持 0 反对 1

使用道具 举报

15

主题

37

帖子

143

积分

注册会员

Rank: 2

积分
143
沙发
发表于 2014-9-30 14:52:10 | 只看该作者
不明觉厉.能在JS中修改变量的值不嘛.这下又要学习C#了.
回复 支持 反对

使用道具 举报

14

主题

120

帖子

947

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
947
板凳
 楼主| 发表于 2014-9-30 17:43:12 | 只看该作者
lefengkuang2 发表于 2014-9-30 14:52
不明觉厉.能在JS中修改变量的值不嘛.这下又要学习C#了.

暂时不会增加js对变量的修改功能
回复 支持 反对

使用道具 举报

11

主题

47

帖子

199

积分

注册会员

Rank: 2

积分
199
地板
发表于 2014-12-5 20:10:07 | 只看该作者
:victory::victory::victory:
回复 支持 反对

使用道具 举报

0

主题

3

帖子

10

积分

新手上路

Rank: 1

积分
10
5#
发表于 2014-12-17 03:42:15 | 只看该作者
请版主完善教程,是不是支持所有代码还是仅仅是对存在变量的操作》

动态生成报错
public static void Execute(Dictionary<string, string> stringDic,Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
        {
          List<string> yyy=new List<string>();
          yyy.Add('kkk');
          listDic.Add("C#",yyy);
         
        }

手动先新建list变量后fu赋值报错
public static void Execute(Dictionary<string, string> stringDic,Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
        {
         
          listDic['test'].Add("C#");
         
        }

我就是需要处理一个通用的分隔符字符串如  
gg/hghh.jpg|fff/hhh.jpg|hgf/jhg.jpg|
gg/hg56hh.jpg|ffghf/hhh.jpg|hkjgf/jhjhg.jpg|

变成一个list变量,该再怎么处理
回复 支持 反对

使用道具 举报

0

主题

3

帖子

10

积分

新手上路

Rank: 1

积分
10
7#
发表于 2014-12-17 23:38:30 | 只看该作者
晕,写多了php随意,net这个字符跟字符串区别这么严格,采集器功能比火车头还强

为了大家少走弯路,把成功代码写下,大家参考,问下版主,这个动态生成的变量没办法,后面步骤中调用,必须要事先写成的变量,如下面代码中变量ff就是:
public static void Execute(Dictionary<string, string> stringDic,Dictionary<string, List<string>> listDic, Dictionary<string, int> intDic)
        {
int j=0;
foreach(string pic in  listDic["ls"]){
        string[] pics=pic.Split('|');

        foreach(string p in pics){
      if(string.IsNullOrEmpty(p)) continue;
         j++;
          stringDic.Add("pic"+j.ToString(),p.ToString());
         stringDic["ff"]=p.ToString()+j.ToString();
             listDic["lankii"].Add(p.ToString());
           }


          }


        }
回复 支持 反对

使用道具 举报

0

主题

3

帖子

10

积分

新手上路

Rank: 1

积分
10
8#
发表于 2014-12-17 23:40:30 | 只看该作者
变量ff成功赋值获得图片地址
回复 支持 反对

使用道具 举报

1

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
9#
发表于 2014-12-22 22:26:43 | 只看该作者
mark
回复

使用道具 举报

1

主题

2

帖子

19

积分

新手上路

Rank: 1

积分
19
10#
发表于 2015-1-23 00:03:23 | 只看该作者
学习了,感谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|火车浏览器  

GMT+8, 2024-4-20 19:10 , Processed in 0.089295 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表