如何查找说明中的所有关键字并将其替换为大写版本 [英] How to find all the keywords in the description and replace them with their uppercase version

查看:92
本文介绍了如何查找说明中的所有关键字并将其替换为大写版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的文字'描述和一个关键字列表

我想在描述中找到关键字并用大写版本替换它们并在更改后返回描述



I have a long text 'description and a list of keywords
I want to find the keywords in the description and replace them with their upper case version and return the description after the changes

public static string UpperCaseAllTheKeywords(string description, string[] keywords)
        {
            var result3 = description.Split(' ');
            var result = new List<int>();
            foreach (var y in keywords)
            {
                var result2 = description.AllIndicesOf(y);
                var result0 = result.Concat(result2);
                foreach (var i in result0)
                {

                    var result = result3.ElementAt(i).ToUpper();
                }
            }

            return result3.ToString("");

        }

What I have tried:

<pre><pre>public static string UpperCaseAllTheKeywords(string description, string[] keywords)
        {
            var result3 = description.Split(' ');
            var result = new List<int>();
            foreach (var y in keywords)
            {
                var result2 = description.AllIndicesOf(y);
                var result0 = result.Concat(result2);
                foreach (var i in result0)
                {

                    var result = result3.ElementAt(i).ToUpper();
                }
            }

            return result3.ToString("");

        }

推荐答案

而不是

Instead of
var result = result3.ElementAt(i).ToUpper();

使用:

Use:

result3.ElementAt(i) = result3.ElementAt(i).ToUpper();


这篇关于如何查找说明中的所有关键字并将其替换为大写版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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