Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to remove a random word from a string in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str = "I'm not clumsy The floor just hates me";
        
        string result = RemoveRandomWord(str);
        
        Console.WriteLine(result);
    }

    static string RemoveRandomWord(string input) {
        Random random = new Random();
        
        string[] words = input.Split(' ');
        if (words.Length == 0) return input;

        int randomIndex = random.Next(words.Length);
        words = words.Where((word, index) => index != randomIndex).ToArray();
        
        return string.Join(" ", words);
    }
}



/*
run:
 
I'm not clumsy The floor just me
 
*/

 



answered May 4, 2025 by avibootz
...