在C#中的东西的功能实现东西、功能

由网友(妳是我的獨家回憶)分享简介:我需要知道的任何C#是否等于SQL函数 的东西 ,该更换输入字符串转换成原始字符串基础上,开始和长度给出。I need to know any whether c# has any function equal to sql function stuff, which replace the input string...

我需要知道的任何C#是否等于SQL函数 的东西 ,该更换输入字符串转换成原始字符串基础上,开始和长度给出。

I need to know any whether c# has any function equal to sql function stuff, which replace the input string into the original string based on the start and length given.

主编的加样:

select stuff('sad',1,1'b')

select stuff(original string, start point, length,input string)

输出将坏。

推荐答案

有没有内置的方法来做到这一点,但你可以写一个扩展方法:

There is no built-in method to do this, but you could write an extension method:

static class StringExtensions
{
    public static string Splice(this string str, int start, int length,
                                string replacement)
    {
        return str.Substring(0, start) +
               replacement +
               str.Substring(start + length);
    }

}

的用法是这样:

The usage is as such:

string sad = "sad";
string bad = sad.Splice(0, 1, "b");

请注意,在一个字符串在C#中的第一个字符是数字0,而不是1,在你的SQL实例。

Note that the first character in a string in C# is number 0, not 1 as in your SQL example.

如果你愿意,你可以调用过程的方法的东西,但可以说是拼接名字有点更清晰的(虽然它不经常使用两种)。

If you wish, you can call the method Stuff of course, but arguably the Splice name is a bit clearer (although it's not used very often either).

阅读全文

相关推荐

最新文章