Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3402488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:08:39+00:00 2026-05-18T05:08:39+00:00

My aim is to Sanitize a string. The class should do: trim an input

  • 0

My aim is to “Sanitize a string”.

The class should do:

  • trim an input
  • make the first letter upper case.

Could you please tell me:

  • Is there a way to better code it?
  • Would it make sense to use a PARAMETER for a method like: CapitalizeFirstLetterTrim(string x)

    • when I initiate an object I need write a lot of code like below, any other way to make it shorter?

      UserInputSanitizer myInput = new UserInputSanitizer();
      myInput.Input = "            ciao world";
      string ouput = myInput.CapitalizeFirstLetterTrim();
      

Useful resource http://msdn.microsoft.com/en-us/library/bb311042.aspx

———– CLASS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebProject.Core.Utilities
{
    public class UserInputSanitizer
    {
        // Backing variables
        private string _input;
        // Properties
        public string Input
        {
            set { _input = value; }
        }
        private string _output;

        // Backing variables
        // Properties
        public string Output
        {
            get { return _output; }
        }

        public string CapitalizeFirstLetterTrim()
        {
            // Trim
            _input.Trim();
            // Make First letter UpperCase and the rest levae lower case
            _output = _input.Substring(0, 1).ToUpper() + _input.Substring(1);
            return Output;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:08:39+00:00Added an answer on May 18, 2026 at 5:08 am

    I would use an extension method for the string class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace WebProject.Core.Utilities
    {
        public static class StringExtensions
        {
            public static string Sanitize(this string s)
            {
                //your code to sanitize your string, for example
                if(s == null) throw new ArgumentNullException("s");
                var trimmed = input.Trim();
                return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(trimmed);
            }
        }
    }
    

    Then you can use:

    string s = "    UnsanitizedString";
    s = s.Sanitize();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my aim is to compare the first names with the title of an img-element
The aim is to not even start $foo if there is no input. This
function aim() { var mousex = ? } <div class=gameArea onmousemove=aim();> </div> I can't
The aim of the module described below is to implement a module which once
My aim is to produce an array, which I can use to add section
My aim is to show the text - Welcome username The username info is
My aim is to load an OpenLayers map using an external JS file. In
My aim is to have a <div> with a fixed size (dynamically set through
I'm currently building a web app (atop Ruby on Rails), which will let users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.