XmTextGetSubstring() to get a copy of a portion of the text in a Text widget.
The alternative to XmTextGetString() is the Xt function XtVaGetValues(). The Text widget responds to
XtVaGetValues() by allocating memory and returning a copy of the text. As a result, this data must be freed after
use. This use of the GetValues() method is different from most other resources. For most resources,
XtVaGetValues() returns a pointer to internal data that should be treated as read−only data. In order to avoid
memory leaks, you need to be sure to free the memory that is allocated by XtVaGetValues() for the XmNvalue
resource, as shown in the following code fragment:
char *text;
XtVaGetValues (text_w, XmNvalue, &text, NULL);
/* manipulate text in whatever way is necessary */
...
/* free text or there will be a memory leak */
XtFree (text);
Getting the value of a Text widget can be an expensive operation if the widget contains a large amount of text. In all
situations, whenever text is retrieved from the Text widget with any function, the length of time the data is valid is
only guaranteed until the next Xt call into the same Text widget; what any particular call might do to the internal text
stream is undefined, and that information will not be reflected in the current character pointer handle you may have.
A Text widget may contain an arbitrarily large amount of text, assuming that there is enough memory on the computer
running the client application. The text for a widget is not stored on the X server; ...