Trimming String C#.NET, ASP.NET Remove all extra space

Task:  Remove Extra spacing from a string(paragraph). Trimming the space from String.

Description:  Here I create a code for removing extra space from a string as Trimming externally and as well as internally also. So that two and more consecutive space will remove.

C#.NET,SQL SERVER, ASP.NET HELP

      public string replacespace(string s)
    {
        int l = s.Length;
        char[] ch = s.ToCharArray();
        s = "";
        for (int i = 0; i < l - 1; i++)
        {
            if (ch[i] == ' ')
            {
                if (ch[i + 1] == ' ')
                { }
                else
                    s = s + ch[i];
            }
            else
                s = s + ch[i];
        }
        if (ch[l - 1] != ' ')
            s = s + ch[l - 1];
        return (s);
    }


No comments:

Post a Comment