[Cuis-dev] find and replace
Benoit St-Jean
bstjean at yahoo.com
Sun Dec 15 12:41:00 PST 2024
You need something like this.
Obviously, make backups of your stuff BEFORE trying this code! Use at
your own risk!
| methodReferences replacementString stringToReplace |
Transcript clear.
stringToReplace := '123456789012312312 sin'.
replacementString := '2112 abs'.
methodReferences := Smalltalk allMethodsSourceStringMatching: ('*',
stringToReplace, '*').
methodReferences do: [:each | | class newSourceCode |
class := each classIsMeta
ifTrue: [(Smalltalk at: each
classSymbol) class]
ifFalse: [Smalltalk at: each
classSymbol ].
sourceCode := class sourceCodeAt: each
methodSymbol.
newSourceCode := sourceCode
copyReplaceAll: stringToReplace with: replacementString.
[class compile: newSourceCode]
on: SyntaxErrorNotification
do: [: ex | Transcript cr; show:
class name, '>>', each methodSymbol]
]
On 2024-12-14 19:46, Mark Volkmann via Cuis-dev wrote:
> Is there a provided way to find all occurrences of a given string in a
> method implementation and replace them with a given string? I've
> searched for that and couldn't find it. I don't imagine I would use it
> often, but one use case is replacing all occurrences of four spaces
> with a tab character when I paste in code from outside of the image.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20241215/8c224b74/attachment.htm>
More information about the Cuis-dev
mailing list