First you need the DBText object itself. If you have the two points p1 and p2 of the enclosing rectangle you can use them to retrieve a selection set that contains the DBText. Next have to find the indices of the first and last character that is within the rectangle.
I would suggest to create a DBText object with the same properties as the selected one, and evaluate its extents with different TextString lengths:
Point3d p1, p2; // The selected Points.
// p1 must be "minpoint" and p2 "maxpoint": (p1[k] < p2[k]) must hold for all k
DBText txtOrig = ... // Your text object
DBText txt = txtOrig; // temporary copy of the text object
Extents3d extPrev = new Extents3d();
int iFirst = -1, iLast = -1; // Index of first and last character within [p1 p2]
for (int n=1; n<=txtOrig.TextString.Length; ++n)
{
// Analyze the extents of a DBText with the first n characters of the original text
txt.TextString = txtOrig.TextString.Substring(0, n);
Extents3d ext = txt.GeometricExtents;
extPrev = ext;
// Get the extents of the n-th character
Extents3d ext_n = new Extents3d();
if (n == 0)
ext_n = ext;
else
{
Point3d min = new Point3d(extPrev.MaxPoint.X, ext.MinPoint.Y, ext.MinPoint.Z);
ext_n.Set(min, ext.MaxPoint);
}
// Does ext_n overlap with the selected rectangle?
if (ext_n.MaxPoint.X > p1.X && ext_n.MinPoint.Y < p2.X ) // within X-extents?
{
// n-th char is within the [p1 p2] rectangle
if (iFirst < 0)
iFirst = n;
iLast = n;
}
// Now you can replace chars iFirst...iLast
}
Note that the code above doesn't consider multiline text and text rotation.
Thomas Brammer ● Software Developer ● imos AG ● LinkedIn ● 
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.