Results 1 to 8 of 8

Thread: [C#] Improving my ToProper() Function

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    [C#] Improving my ToProper() Function

    Can you code it better?

    Code:
    public string ToProper(string src)
    {
    	string[] s = src.Split(new char[] { ' ' });
    	string retval = String.Empty;
    	int n = 0;
    
    	foreach (string str in s)
    	{
    		if (str == String.Empty)
    		{
    			retval += " ";
    		}
    		else
    		{
    			retval += (str[0].ToString().ToUpper() +
    				str.Substring(1, str.Length - 1).ToLower() +
    				(n < s.Length - 1 ? " " : ""));
    		}
    
    		n++;
    	}
    
    	return retval;
    }
    Last edited by wey97; Oct 12th, 2006 at 02:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width