Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
TextString = FirstSelection.String
UCaseStr = UCase(TextString)
FirstSelection.String = UCaseStr
Doc = ThisComponent
oText = Doc.Text
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
Curs = oText.createTextCursorByRange(FirstSelection)
Curs.collapseToStart
Curs.gotoStartOfWord(False)
Comp = oText.compareRegionEnds(Curs.End,FirstSelection)
While Comp = 1
Curs.goRight(1,True)
Curs.String = UCase(Curs.String)
Curs.gotoNextWord(False)
Comp = oText.compareRegionEnds(Curs.End,FirstSelection)
WendSub TitleCase
Doc = ThisComponent
oText = Doc.Text
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
aSplit = Split(FirstSelection.String)
For i = lBound(aSplit) to uBound(aSplit)
st = aSplit(i)
Mid(st,1,1,UCase(Mid(st,1,1))
aSplit(i) = st
Next
FirstSelection.String = Join(aSplit)
End SubFor each st in aSplit
Mid(st,1,1,UCase(Mid(st,1,1))
Print st
'How do you get this element of the array to adopt the change in the string?
Nexti=0
For Each st in aSplit
Mid(st,1,1,UCase(Mid(st,1,1))
aSplit(i) = st
i = i + 1
Next
OldString = "A set of words that is long"
aSplit = Split(OldString)
NewString = ""
For Each st in aSplit
Mid(st,1,1,UCase(Mid(st,1,1))
If len(NewString) <> 0 then
NewString = NewString + " " + st
Else
NewString = st
End if
Next
NewString = NewString + st + " "
Next
Print NewString,Len(NewString)
'Trim(NewString) REM Why doesn't this work??
NewString = Right(NewString,Len(NewString)-1)
Print NewString,Len(NewString)Finally, I think your method will not capitalize a word if it is proceeded by a parenthesis or quotation mark.
sub TitleCase
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "CaseMap"
args1(0).Value = 3
dispatcher.executeDispatch(document, ".uno:CaseMap", "", 0, args1())
end subsub All_Caps
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "CaseMap"
args1(0).Value = 1
dispatcher.executeDispatch(document, ".uno:CaseMap", "", 0, args1())
end subsub No_Caps
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "CaseMap"
args1(0).Value = 0
dispatcher.executeDispatch(document, ".uno:CaseMap", "", 0, args1())
end subSub CaseToggle
Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
TextString = FirstSelection.String
If UCASE(TextString) = TextString then
TextString = LCASE(TextString)
Else
TextString = UCASE(TextString)
End if
FirstSelection.String = TextString
End subSub CaseToggle
rem Read the case state of the current selection
If ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = 1 then
rem If it is upper case, set to lower
ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = 0
Else
rem If it is lower case, set to upper
ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = 1
End if
rem That's all!
End subSub CaseCycle
rem Read the case state of the current selection.
rem If it's SmallCaps (the highest possible CaseMap value -
rem see http://api.openoffice.org/docs/common/ref/com/sun/star/style/CaseMap.html)
rem then set CaseMap=0, which is not necessarily lower case
rem but whatever the underlying text was without any caps effects
If ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = 4 then
ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = 0
Else
rem If it wasn't SmallCaps cycle to the next value
ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap = ThisComponent.CurrentSelection.getByIndex(0).CharCaseMap + 1
End if
rem That's all!
End subReturn to OpenOffice Basic, Python, BeanShell, JavaScript
Users browsing this forum: No registered users and 2 guests