当前位置:网站首页>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 is the ISM model analyzed?
- linux中的mysql有10061错误怎么解决
- Unity Addressable批量管理
- ¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
- 106. 简易聊天室9:使用 Socket 传递音频
- 各种同步学习笔记
- QSS 不同风格的按钮
- tp6自动执行的文件是哪个?tp6核心类库有什么作用呢?
- Paper:Generating Hierarchical Explanations on Text Classification via Feature Interaction Detection
- Prepare these before the interview. The offer is soft. The general will not fight unprepared battles
猜你喜欢

LVS-DR模式多网段案例

Prepare these before the interview. The offer is soft. The general will not fight unprepared battles

How to calculate the correlation coefficient and correlation degree in grey correlation analysis?

What do various optimizers SGD, adagrad, Adam and lbfgs do?

【操作教程】TSINGSEE青犀视频平台如何将旧数据库导入到新数据库?

How to calculate the independence weight index?

compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).

C language "recursive series": recursive implementation of 1+2+3++ n

GPU calculation

About i/o -- the relationship between memory and CPU and disk
随机推荐
How to calculate the positive and negative ideal solution and the positive and negative ideal distance in TOPSIS method?
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
紧急行政中止令下达 Juul暂时可以继续在美国销售电子烟产品
C language: count the number of characters, numbers and spaces
声纹技术(三):声纹识别技术
How to calculate critical weight indicators?
Summary of hardfault problem in RTOS multithreading
Unity Addressable批量管理
Hyper-v:Hyper-v 第 1 代或第 2 代虚拟机
关于I/O——内存与CPU与磁盘之间的关系
Iframe is simple to use, iframe is obtained, iframe element value is obtained, and iframe information of parent page is obtained
IC研发常用英文术语缩写
What are the indicators of entropy weight TOPSIS method?
Sharepoint:sharepoint server 2013 and adrms Integration Guide
QSS 不同风格的按钮
通过客户经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
To achieve good software testing results, it is a prerequisite to build a good testing environment
【515. 在每个树行中找最大值】
RTOS 多线程下hardfault问题总结
获取扫码的客户端是微信还是支付宝