OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problem with a selection that contains a number

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Mon Feb 05, 2007 4:59 am    Post subject: Problem with a selection that contains a number Reply with quote

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
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Mon Feb 05, 2007 1:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Tue Feb 06, 2007 12:44 am    Post subject: Reply with quote

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
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Feb 06, 2007 11:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group