日期:2014-05-17  浏览次数:20843 次

找出一个逗号分隔单词的字符串中带有问号的地方,带有问号的单词加引号
sdfsdf,dsfsdf?,dsfsdfsd,dfsdfsdf,dfs?dsfsd

处理后
sdfsdf,"dsfsdf?",dsfsdfsd,dfsdfsdf,"dfs?dsfsd"

用C#实现

------解决方案--------------------
运行是你想要的结果!
string str = "sdfsdf,dsfsdf?,dsfsdfsd,dfsdfsdf,dfs?dsfsd";
            string strTmp = "";
            string[] strAll = str.Split(',');
            for (int i = 0; i < strAll.Length; i++)
            {
                Regex reg = new Regex("[?/]+");
                Match m = reg.Match(strAll[i]);
                if (!m.Success)
                {
                    strTmp += strAll[i] + ",";
                }
                else
                {
                    strTmp += "'" + strAll[i] + "',";
                }
            }
            MessageBox.Show(strTmp);
------解决方案--------------------

string a = "sdfsdf,dsfsdf?,dsfsdfsd,dfsdfsdf,dfs?dsfsd";
string b = null;
a.Split(',').ToList().ForEach(o => b += o.Contains("?") ? "\"" + o + "\"," : o + ",");
Console.WriteLine(b.Remove(b.Length - 1, 1));

------解决方案--------------------
            string str = "sdfsdf,dsfsdf?,dsfsdfsd,dfsdfsdf,dfs?dsfsd";
            string result = Regex.Replace(str, @"(?<wo