小编Tan*_*ank的帖子

使用for循环替换.NET C#模型中的字符串字符

我是.NET MVC的新手,来自PHP/Java/ActionScript.

我遇到的问题是.NET模型和get{}.我不明白为什么我的Hyphenize字符串将SomeText截断的值返回到64个字符,但不替换数组中定义的任何字符.

模型 - 这应该SomeText用一个简单的连字符替换某些字符-:

    public string SomeText{ get; set;} // Unmodified string

    public string Hyphenize{ 
        get {
            //unwanted characters to replace
            string[] replace_items = {"#", " ", "!", "?", "@", "*", ",", ".", "/", "'", @"\", "=" };
            string stringbuild = SomeText.Substring(0, (SomeText.Length > 64 ? 64 : SomeText.Length));

            for (int i = 0; i < replace_items.Length; i++)
            {
                stringbuild.Replace(replace_items[i], "-");
            }

            return stringbuild;
        }

        set { } …
Run Code Online (Sandbox Code Playgroud)

c# variables asp.net-mvc

0
推荐指数
1
解决办法
1929
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

variables ×1