Writer Macro: working with current selection

I’m trying to capture the current selection in a Writer doc, then test the end points for spaces. If they are spaces I want to trim the Selection back, until the endpoints are non-spaces.

I got this from OOo’s wiki:

oCurSelection = thisComponent.getCurrentSelection()
if oCurSelection.supportsService("com.sun.star.text.TextRanges") then
   nCount = oCurSelection.Count
   if nCount = 1 then
      oTextRange = oCurSelection.getByIndex(0)
      'Do some action on oTextRange
   else
      for i = 0 to nCount - 1
         oTextRange = oCurSelection.getByIndex(i)
         'Do some action on oTextRange
      next
   end if
end if

The oTextRange variable contains the current Selection in its “String” component.

But I don’t have a clue how to go to the end points, test them for “spacehood” and trim them back if necessary.

I have consulted Andrew’s book, which unfortunately only makes me more confused. And I didn’t see anything online.

Which of the books Andrew you have in mind? Chapter 7.2. Text Cursors, What Are They?

I don’t understand you… if you show an example, I help you with the code

Best regards

It seems to me that he wants to collapse each of the selections to Trim(oSel.getString()) - without spaces before and after - and then highlight them (reselect it)