© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
10 replies
Muhammad Hammad

question about strings & stringbuilder!

this is the code
namespace Palindrome_Finder
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Our Palindrome Finder");
            Console.WriteLine("Enter a Word or a Sentence to find if it's a Palindrome");
            string UserInput = Console.ReadLine();
            string processedInput=cleaner(UserInput);
            Console.WriteLine($"Reversed Input: {processedInput}");
            Console.ReadLine();

        }
        static string cleaner(string input)
        {
            string cleanedInput = input;
            Console.WriteLine($" Original Input:{cleanedInput}");
            foreach (char c in cleanedInput)
            {
               
                if(char.IsLetterOrDigit(c))
                {
                   cleanedInput.Append(c);
                }
               
            }
            string reversedInput = new string(cleanedInput.Reverse().ToArray());
            return reversedInput;

        }

    }
}
namespace Palindrome_Finder
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Our Palindrome Finder");
            Console.WriteLine("Enter a Word or a Sentence to find if it's a Palindrome");
            string UserInput = Console.ReadLine();
            string processedInput=cleaner(UserInput);
            Console.WriteLine($"Reversed Input: {processedInput}");
            Console.ReadLine();

        }
        static string cleaner(string input)
        {
            string cleanedInput = input;
            Console.WriteLine($" Original Input:{cleanedInput}");
            foreach (char c in cleanedInput)
            {
               
                if(char.IsLetterOrDigit(c))
                {
                   cleanedInput.Append(c);
                }
               
            }
            string reversedInput = new string(cleanedInput.Reverse().ToArray());
            return reversedInput;

        }

    }
}

people say me use stringbuilder instead of appending to a string they say the way I did can be slower and resource consuming he don't reply further thought he is busy man can any gentleman teach me why is it he just said strings are immutable which is also what I don't think cuz I can add new value to strings I can assign new value to strings why they say they are immutable! help me this is confusing for me!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Stringbuilder remove
C#CC# / help
3y ago
✅ StringBuilder in C#
C#CC# / help
12mo ago
✅ Question about serialization
C#CC# / help
7mo ago
✅ Question about learning
C#CC# / help
8mo ago