当前位置:网站首页>C#启动程序传递参数丢失双引号,如何解决?
C#启动程序传递参数丢失双引号,如何解决?
2022-06-25 08:01:00 【先生沉默先】
c#启动程序之后传递的参数没有双引号
bug展示
C#程序启动代码
static void Main(string[] args)
{
Dictionary<string, string> dic = new Dictionary<string, string>();//创建参数传递对象
dic.Add("dst", "ddd");
dic.Add("dasdst", "ddd");
var requesDataStr = JsonConvert.SerializeObject(dic);//序列化对象,用于参数的传递
ProcessStartInfo startInfo = new ProcessStartInfo();//创建一个启动程序的ProcessStartInfo
startInfo.FileName = "MD5Encryption.exe"; //启动的应用程序名称
startInfo.Arguments = @requesDataStr;//给启动的程序传递的参数
Process.Start(startInfo);//启动程序
Console.WriteLine("程序启动啦");
Console.ReadKey();
}
C#被启动的程序的代码
static void Main(string[] args)
{
Console.WriteLine(args[0]);//仅打印一下传递过来的字符串就行了
Console.ReadKey();
Console.ReadKey();
}
效果就是上面的图片
解决方案
将里面的双引号进行转义
代码在23行
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("dst", "ddd");
dic.Add("dasdst", "ddd");
var requesDataStr = JsonConvert.SerializeObject(dic);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "MD5Encryption.exe"; //启动的应用程序名称
requesDataStr = requesDataStr.Replace("\"","\\\"");
startInfo.Arguments = @requesDataStr;
Process.Start(startInfo);
Console.WriteLine("程序启动啦");
Console.ReadKey();
将字符串替换为另外一个字符串
代码第24行字符串替换
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("dst", "ddd");
dic.Add("dasdst", "ddd");
var requesDataStr = JsonConvert.SerializeObject(dic);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "MD5Encryption.exe"; //启动的应用程序名称
requesDataStr = requesDataStr.Replace("\"", "#");
startInfo.Arguments = @requesDataStr;
Process.Start(startInfo);
Console.WriteLine("程序启动啦");
Console.ReadKey();
字符串再次替换
static void Main(string[] args)
{
args[0] = args[0].Replace("#", "\"");
Console.WriteLine(args[0]);
}
修改字符串的编码格式
我不会,也暂时用不到这种方式。
不会就评论或者私信
。
边栏推荐
- 从别人库里拷贝的游戏如何再自己的库里显示
- How to interpret the information weight index?
- 五、项目实战---识别人和马
- C language: count the number of characters, numbers and spaces
- About i/o -- the relationship between memory and CPU and disk
- 某视频网站m3u8非感知加密分析
- How to analyze the grey prediction model?
- mysql之Unknown table ‘COLUMN_STATISTICS‘ in information_schema (1109)
- QSS 不同风格的按钮
- Problems caused by Gil problems and Solutions
猜你喜欢
How to calculate the correlation coefficient and correlation degree in grey correlation analysis?
【无标题】**数据库课设:三天完成学生信息管理系统**
wav文件(波形文件)格式分析与详解
City Chain technology platform, really Realizing value Internet reconstruction!
The city chain technology platform is realizing the real value Internet reconstruction!
从别人库里拷贝的游戏如何再自己的库里显示
某次比赛wp
二、训练fashion_mnist数据集
Getting to know the generation confrontation network (11) -- using pytoch to build wgan to generate handwritten digits
How to calculate critical weight indicators?
随机推荐
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
cazy長安戰役八卦迷宮
Exchange: manage calendar permissions
¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
初识生成对抗网络(11)——利用Pytorch搭建WGAN生成手写数字
What is the file that tp6 automatically executes? What does the tp6 core class library do?
Object.defineProperty也能监听数组变化?
How to calculate the positive and negative ideal solution and the positive and negative ideal distance in TOPSIS method?
声纹技术(四):声纹识别的工程部署
Problems caused by Gil problems and Solutions
Word2vec, phrases, phraser, keyedvectors commonly used in gensim
Rank sum ratio (RSR) index calculation
What are the indicators of entropy weight TOPSIS method?
mysql之Unknown table ‘COLUMN_STATISTICS‘ in information_schema (1109)
五、项目实战---识别人和马
从别人库里拷贝的游戏如何再自己的库里显示
【MYSQL】索引的理解和使用
Find the nearest common ancestor (Sword finger offer) of two nodes in the binary tree (search tree)
Emergency administrative suspension order issued Juul can continue to sell electronic cigarette products in the United States for the time being
atguigu----18-组件