当前位置:网站首页>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]);
}
修改字符串的编码格式
我不会,也暂时用不到这种方式。
不会就评论或者私信

。
边栏推荐
- 某视频网站m3u8非感知加密分析
- tp5与tp6的区别是啥呀?
- OpenFOAM:底层
- What are the indicators of DEA?
- atguigu----01-脚手架
- 软件工程复习题
- City Chain technology platform, really Realizing value Internet reconstruction!
- 35岁腾讯员工被裁员感叹:北京一套房,存款700多万,失业好焦虑
- Sharepoint:sharepoint server 2013 and adrms Integration Guide
- [515. find the maximum value in each tree row]
猜你喜欢

Lvs-dr mode multi segment case

C language: find all integers that can divide y and are odd numbers, and put them in the array indicated by B in the order from small to large

About i/o -- the relationship between memory and CPU and disk

如何成为一名软件测试高手? 月薪3K到17K,我做了什么?

What about the exponential smoothing index?

What are the indicators of VIKOR compromise?

故障:Outlook 收发邮件时的 0x800CCC1A 错误

cazy长安战役八卦迷宫

五、项目实战---识别人和马

EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
随机推荐
atguigu----01-脚手架
微信小程序_7,项目练习,本地生活
五、项目实战---识别人和马
三、自动终止训练
cazy長安戰役八卦迷宮
打新债安全性有多高啊
Problems caused by Gil problems and Solutions
TrendMicro:Apex One Server 工具文件夹
如何设计测试用例
nodejs 使用Express框架demo
在哪个平台买股票开户安全?求分享
GPU calculation
openid是什么意思?token是什么意思?
How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it
C language: count the number of words in a paragraph
What about the exponential smoothing index?
Analysis of a video website m3u8 non perceptual encryption
各种同步学习笔记
linux中的mysql有10061错误怎么解决
Advanced technology Er, meet internship position information