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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:57:39+00:00 2026-05-15T10:57:39+00:00

I have a text like this: My name is Bob and I live in

  • 0

I have a text like this:

My name is Bob and I live in America.

I have some reference to the characters of this string, for example:

from 3 to 7 chars, deleted
at 3 char, added "surname"
from 20 to 25, deleted
at 25 char ....

but these statements aren’t ordered (and I can’t order them).

So, this is the question: how can I modify the text without losing the reference of the characters?
For example, if I apply the first sentence, my text became:

My is Bob and I live in America.

and my third sentence doesn’t work correctly anymore, cause I’ve lost the reference to the original 20th character.

Keep in mind that the text is pretty long, so I can’t use any indexes…

  • 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-15T10:57:40+00:00Added an answer on May 15, 2026 at 10:57 am

    First off, if this statement is true, the situation is hopeless:

    but these statements aren’t ordered (and I can’t order them).

    An unordered list of patch statements could lead to a conflict. It will not be possible to decide what the right answer is in an automated fashion. For instance, consider the following situation:

             0         1         2
     index:  012345678901234567890
     text:  "apple banana coconuts"
        - delete 5 characters from index 10
        - add "xyz" at index 10
        - delete 10 characters from index 5
    

    You will wind up with different results depending on what order you execute these statements.

    • For instance, if you apply (1), then (2), then (3), you wind up with “apple banaconuts” –> “apple banaxyzconuts” –> “apple uts”.

    • But if you apply (3), then (2), then (1), you wind up with “apple onuts” –> “apple onutsxyz” –> [error — there aren’t enough characters to delete!].

    Either you need a repeatable, agreed-upon ordering of the statements, or you cannot proceed any further. Even worse, it turns out that discovering which orderings are valid (for example, eliminating all orderings where an impossible statement occurs, like “delete 10 characters from index 20”, when there is no index 20) is an undecidable computer science problem.


    If it turns out that the patches can be applied in a specific order (or at least in a repeatable, agreed-upon, deterministic order), the situation improves but is still obnoxious. Because the indices in any “patch” could be invalidated by any previous one, it’s not going to be possible to straightforwardly apply each statement. Instead, you’ll have to implement a small, pseudo-diff. Here’s how I’d do it:

    • Scan through the list of patch-statements. Build a list of operations. An operation is an object with a command and some optional arguments, and an index to apply that command to. For example, your operations might look like:
      DeleteOperation(index 3, length 4)
      AddOperation(index 3, text "surname")
      DeleteOperation(index 20, length 5)
    
    • As you perform operations, keep a reference to the original string and store a “dirty pointer”. This is the latest contiguous index in the string which has had no operations performed on it. Any operation you perform whose index exceeds the dirty pointer must first be pre-processed.

    • If you encounter a clean operation, one whose index is less than or equal to the dirty pointer, you can apply it with no further work. The dirty pointer now moves to that operation’s index.

    • If you encounter a dirty operation, one whose index is greater than the dirty pointer, you’ll have to do some work before you can apply it. Determine the real index of where the operation should be applied by looking at the previous operations, then make the appropriate offset and apply it.

    • Execute each operation in turn until there are no more operations to execute.

    The result is your transformed string.

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

Sidebar

Related Questions

I have this string: My name is <b>Bob</b>, I'm <b>20</b> years old, I like
I have a text string like this: <dt> <span> <tag:text name=fee /> </span> </dt>
I have a bunch of chat logs that look like this: name: some text
I have a text like this [name:roccos] [phone:123324324] [tags:abc def ghi] [id:value] How can
I have text to localize like this <p>Please enter your user name and password.
I have a text file which contains something like this: Hello, my name is
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I have a table where a record looks like this varchar(255) Name varchar(255) Text
i have a text boxes in every row with same name like this <tr>
I have a chatlog file that looks like this (name represents screenames and text

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.