格式化字符串列表 [英] format list of string

查看:110
本文介绍了格式化字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我有

列表< string>列表

,它包含值

Hi
i have
List<string> list
and it contains value as

[2] "\"Test1\":\"ascdfvgv\"" string
[3] "\"Test2\":\"wqaasss\"" string
[4] "\"Test3\":\"bababalnbala\"" string



如何将其拆分为一个简单的字符串数组而不用\和:


how to split this into a simple array of a string without \ and :

推荐答案

你好Maulikshah,



您可以使用以下代码从字符串列表中删除\和:

Hi Maulikshah,

You could use the below code to remove \ and : from the list of string
List<string> temp = new List<string>();
            Dictionary<string, string> output = new Dictionary<string, string>();
            temp.Add("\"Test1\":\"ascdfvgv\"");
            temp.Add("\"Test2\":\"wqaasss\"");
            temp.Add("\"Test3\":\"bababalnbala\"");

            for (int i = 0; i < temp.Count; i++)

            {

                temp[i] = temp[i].Replace("\"", "");

                temp[i] = temp[i].Replace(@":", " ");

                temp[j].Split(' ');

                output.Add(temp[j].Split(' ')[0], temp[j].Split(' ')[1]);

            }



            string dicVal = output["Test1"];





输出就像



Output will be like

Test1 ascdfvgv<br />
Test2 wqaasss<br />
Test3 bababalnbala



但你的意思是拆分?你想把数组分成什么?

用你需要的输出更新你的问题所以我可以帮你解决。



希望这会对你有所帮助。



问候,

RK


But what you mean by split? do you want to split the array in to what?
Update your question with your required output so I could help you out.

Hope this helps you a bit.

Regards,
RK


List<string> lst = new List<string>();
       lst.Add("\"Test1\":\"ascdfvgv\"");
       lst.Add("\"Test2\":\"wqaasss\"");
       lst.Add("\"Test3\":\"bababalnbala\"");

       Dictionary<string, string> dict = new Dictionary<string, string>();
       lst.ForEach(k => { dict.Add(k.Replace("\"", "").Split(':')[0], k.Replace("\"", "").Split(':')[1]); });

       string key = "Test1";

       string value = dict[key];


这篇关于格式化字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆