如何有效地除去字符串的一部分 [英] How to remove a part of string effectively
本文介绍了如何有效地除去字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有像A = B和一个字符串; C = D急症= F,如何删除C = D的一部分,得到字符串如A = B急症= F
Have a string like A=B&C=D&E=F, how to remove C=D part and get the string like A=B&E=F?
推荐答案
要么只需更换它扔掉:
input.Replace("&C=D", "");
或使用的解决方案之一,形成你previous问题,从数据结构中删除,并加入它重新走到一起。
or use one of the solutions form your previous question, remove it from the data structure and join it back together.
使用我的code:
var input = "A=B&C=D&E=F";
var output = input
.Split(new string[] {"&"}, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Split('=', 2))
.ToDictionary(d => d[0], d => d[1]);
output.Remove("C");
output.Select(kvp => kvp.Key + "=" + kvp.Value)
.Aggregate("", (s, t) => s + t + "&").TrimRight("&");
这篇关于如何有效地除去字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文