| View previous topic :: View next topic |
| Author |
Message |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Mon Feb 05, 2007 4:59 am Post subject: Problem with a selection that contains a number |
|
|
Hi,
I have a problem in a macro : if I select the text of a numbered line, and I use the getString() method of the cursor, a character is added.
For example if I have :
1 This is a numbered line
And I select just "This is a numbered line"
The value of the string is : "1This is a numbered line"
So I tried to deal with that bug : if the text is numbered, I delete the first character. But now the problem is with other numbers, like 1.1, 2.1.1 ...
I have to delete the n first characters, where n is the length of the number. But how can I get this length ? |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8976 Location: Lexinton, Kentucky, USA
|
Posted: Mon Feb 05, 2007 1:20 pm Post subject: |
|
|
This will look through the string until it finds a character other than a space, period or number. | Code: | Sub Main
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
For C = 1 to Len(oVC.String)
If ASC(Mid(oVC.String,C,1)) > 57 then Exit For
Next
C = C - 1
Print Right(oVC.String,Len(oVC.String) - C)
End Sub |
|
|
| Back to top |
|
 |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Tue Feb 06, 2007 12:44 am Post subject: |
|
|
And what about this numbering style ?
A) The fellowship of the ring
B) The two towers
C) The return of the king |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8976 Location: Lexinton, Kentucky, USA
|
Posted: Tue Feb 06, 2007 11:46 am Post subject: |
|
|
OK, this one just looks for the ). | Code: | Sub Main
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
For C = 1 to Len(oVC.String)
If ASC(Mid(oVC.String,C,1)) = 41 then Exit For
Next
S = Right(oVC.String,Len(oVC.String) - C) :'Print Len(S)
Print S
End Sub |
Now if you ask me about 1.a.ii or the like I won't have an answer or at least won't go to the trouble of programing it until I personally need it. |
|
| Back to top |
|
 |
|