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

。
边栏推荐
- Swiperefreshlayout+recyclerview failed to pull down troubleshooting
- 初识生成对抗网络(12)——利用Pytorch搭建WGAN-GP生成手写数字
- 声纹技术(四):声纹识别的工程部署
- What are the indicators of VIKOR compromise?
- OpenFOAM:底层
- [summary] 1361- package JSON and package lock JSON relationship
- ¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
- Find the nearest common ancestor (Sword finger offer) of two nodes in the binary tree (search tree)
- wav文件(波形文件)格式分析与详解
- 106. 简易聊天室9:使用 Socket 传递音频
猜你喜欢

Summary of NLP data enhancement methods

Exchange:管理日历权限

NIPS 2014 | Two-Stream Convolutional Networks for Action Recognition in Videos 阅读笔记

2021 "Ai China" selection

各种同步学习笔记

Paper:Generating Hierarchical Explanations on Text Classification via Feature Interaction Detection

C language "Recursion Series": recursively realizing the n-th power of X

声纹技术(六):声纹技术的其他应用

35岁腾讯员工被裁员感叹:北京一套房,存款700多万,失业好焦虑

【操作教程】TSINGSEE青犀视频平台如何将旧数据库导入到新数据库?
随机推荐
[515. find the maximum value in each tree row]
InfluxDB时序数据库
Wechat applet_ 7. Project practice, local life
Stimulsoft Ultimate呈现报告和仪表板
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World
atguigu----18-组件
How to calculate the correlation coefficient and correlation degree in grey correlation analysis?
View all listening events on the current page by browser
Discrimination of configuration, software configuration items and software configuration management items
Swiperefreshlayout+recyclerview failed to pull down troubleshooting
浏览器查看当前页面所有的监听事件
How to calculate the independence weight index?
Measure the current temperature
买股票通过客户经理的开户二维码开户资金是否安全?想开户炒股
声纹技术(一):声纹技术的前世今生
2021 "Ai China" selection
Lvs-dr mode multi segment case
Meaning of Jieba participle part of speech tagging
Unity addressable batch management