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

。
边栏推荐
- Stimulsoft ultimate presents reports and dashboards
- How to calculate the correlation coefficient and correlation degree in grey correlation analysis?
- What do various optimizers SGD, adagrad, Adam and lbfgs do?
- 声纹技术(一):声纹技术的前世今生
- Analysis of a video website m3u8 non perceptual encryption
- nodejs 使用Express框架demo
- 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
- How to calculate critical weight indicators?
- City Chain technology platform, really Realizing value Internet reconstruction!
- Unity addressable batch management
猜你喜欢

C language: count the number of words in a paragraph

Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed

Wechat applet_ 7. Project practice, local life

二、训练fashion_mnist数据集

微信小程序_7,项目练习,本地生活

What are the indicators of VIKOR compromise?

How to calculate critical weight indicators?

How to analyze the grey prediction model?

The city chain technology platform is realizing the real value Internet reconstruction!

如何设计测试用例
随机推荐
Retrieval model rough hnsw
QSS buttons of different styles
在二叉树(搜索树)中找到两个节点的最近公共祖先(剑指offer)
三、自动终止训练
Swiperefreshlayout+recyclerview failed to pull down troubleshooting
EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
What is the difference between TP5 and tp6?
TrendMicro:Apex One Server 工具文件夹
现在网上开通股票账号安全吗?
打新债真的安全吗? 风险大吗
Nips 2014 | two stream revolutionary networks for action recognition in videos reading notes
一、单个神经元网络构建
How is the ISM model analyzed?
How to choose an account opening broker? Is it safe to open an account online?
Beam search and five optimization methods
What are the indicators of VIKOR compromise?
【MYSQL】事务的理解
iframe简单使用 、获取iframe 、获取iframe 元素值 、iframe获取父页面的信息
获取扫码的客户端是微信还是支付宝
IC研发常用英文术语缩写