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 6852673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:25:15+00:00 2026-05-27T01:25:15+00:00

I need to compare a value in a string to what user typed in

  • 0

I need to compare a value in a string to what user typed in a richtextbox.

For example: if a richtextbox holds string rtbText = "aaaka" and I compare this to another variable string comparable = "ka"(I want it to compare backwards). I want the last 2 letters from rtbText (comparable has only 2 letters) to be replaced with something that was predetermined(doesn’t really matter what).
So rtbText should look like this:

rtbText = "aaa(something)"

This doesn’t really have to be compared it can just count letters in comparable and based on that it can remove 2 letters from rtbText and replace them with something else.

UPDATE:
Here is what I have:

int coLen = comparable.Length;
           comparable = null;
           TextPointer caretBack = rtb.CaretPosition.GetPositionAtOffset(coLen, LogicalDirection.Backward);
           TextRange rtbText = new TextRange(rtb.CaretPosition, caretBack);
           string text = rtbText.Text;

rtbText returns an empty string or I get an error for everything longer than 3 characters. What am I doing wrong?

Let me elaborate it a little bit further. I have a listbox that holds replacements for values that user types in rtb. The values(replacements) are coming from there, meaning that I don’t really need to go through the whole text to check values. I just need to check the values right before caret. I am comparing these values to what I have stored in another variable (comparable). What needs to be done

Please let me know if you don’t understand something.
I did my best to explain what needs to be done.
Thank you

  • 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-27T01:25:16+00:00Added an answer on May 27, 2026 at 1:25 am

    gumenimeda, I had similar problems few weeks ago. I found my self doing the following (I asume you will have more than one occurance in the RichTextBox that you will need to change), note that I did it for Windows Forms where I have access directly to the Rtf text of the control, not quite sure if it will work well in your scenario:

    1. I find all the occurancies of the string (using IndexOf for example) and store them in a List for example.
    2. Sort the list in descending order (max index goes first, the one before him second, etc)
    3. Start replacing the occurancies directly in the RichTextBox, by removing the characters I don’t need and appending the characters I need.

    The sorting in step 2 is necessary as we always want to start from the last occurance going up to the first. Starting from the first occurance or any other and going down will have an unpleasant surprise – if the length of the chunk you want to remove and the length of the chunk you want to append are different in length, the string will be modified and all other occurancies will be invalid (for example if the second occurance was in at position 12 and your new string is 2 characters longer than the original, it will become 14th). This is not an issue if we go from the last to the first occurance as the change in string will not affect the next occurance in the list).

    Ofcourse I can not be sure that this is the fastest way that can be used to achieve the desired result. It’s just what I came up with and what worked for me.

    Good luck!

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

Sidebar

Related Questions

I need to compare the value of a column (LASTNAME) with a system variable
I need to compare two value (date) from query . String myFormatString = yyyyMMdd;
I need to compare one given value with a retrieved values. I do this
I need to compare the answer in with the aspnet_membership tables PasswordAnswer value. The
I need to compare two dictionaries and to update another dictionary with unmatched items
I need to compare hash values of two strings. I use string template for
I have a C++ application in which I need to compare two values and
I need to compare strings in shell: var1=mtu eth0 if [ $var1 == mtu
I need to compare 2 strings as equal such as these: Lubeck == Lübeck
I need to compare the integer part of two doubles for inequality and I'm

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.