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

  • SEARCH
  • Home
  • 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 8721221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:11:12+00:00 2026-06-13T07:11:12+00:00

I have a WPF .NET 4 C# RichTextBox and I’m wanting to replace certain

  • 0

I have a WPF .NET 4 C# RichTextBox and I’m wanting to replace certain characters within that text box with other characters, this is to happen on the KeyUp event.

What I’m trying to achieve is replace acronyms with full words, e.g.:

pc = personal computer

sc = starcraft

etc…

I’ve looked a few similar threads, but anything I’ve found hasn’t been successful in my scenario.

Ultimately, I’d like to be able to do this with a list of acronyms. However, I’m having issues with even replacing a single acronym, can anyone help?

  • 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-06-13T07:11:13+00:00Added an answer on June 13, 2026 at 7:11 am

    Because System.Windows.Controls.RichTextBox does not have a property for Text to detect its value, you may detect its value using the following

    string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
    

    Then, you may change _Text and post the new string using the following

    _Text = _Text.Replace("pc", "Personal Computer");
    if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text)
    {
    new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text;
    }
    

    So, it’d look like this

    string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
    _Text = _Text.Replace("pc", "Personal Computer"); // Replace pc with Personal Computer
    if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text)
    {
    new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; // Change the current text to _Text
    }
    

    Remark: Instead of using Text.Replace("pc", "Personal Computer"); you may declare a List<String> in which you save the characters and its replacements

    Example:

        List<string> _List = new List<string>();
        private void richTextBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
    
            string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
            for (int count = 0; count < _List.Count; count++)
            {
                string[] _Split = _List[count].Split(','); //Separate each string in _List[count] based on its index
                _Text = _Text.Replace(_Split[0], _Split[1]); //Replace the first index with the second index
            }
            if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text)
            {
            new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text;
            }
        }
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // The comma will be used to separate multiple items
            _List.Add("pc,Personal Computer");
            _List.Add("sc,Star Craft");
    
        }
    

    Thanks,

    I hope you find this helpful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF .NET 3.5 SP1 application that is in use on at
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab
I have a .Net 4.0 WPF application that requires an embedded database. MS Access
I have a C# WPF (.NET 4.0) application that uses Excel interop to read
I have a WPF (C# and .NET 4) application that has a long running
I'm developing an application in WPF (.NET 4). I have an attached property that
I have a C# WPF .NET 4 application that has an icon in the
I'm kinda new to WPF and .Net programming in general. I have downloaded this
I have a WPF (.NET 3.5) control which renders about 20000 rectangles. This MyControl
I have a wpf datagrid (.NET 4.0) that contains raw data from a database,

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.