This may be helpful to contributors wanting to help:
Legacy Kruti Dev representation
To the OP: Please give relevant information. Most users and contributors in this English forum won’t know anything concerning the transformation of old workarounds for the representation of Hindi scripts to the current Unicode representation.
Attach an example of a text document (.odt) containing parts in KrutiDev. There may be need for experimental steps!
Not knowing anything about the background, users trying to help may waste many hours without a functional result.
There must be a transcription table! Give a link to one! (Best as a spreadsheet.)
Thousands of recorded macros won’t help. One well designed Custom Routine should do.
Ohoho… Well, try this
Sub ReplaceInSelection
There was incorrect code here that didn’t do what it was supposed to -
I removed it so that future readers of the thread wouldn’t use it by mistake.
End Sub
Is the order of searched/replaced items proper? 2nd is k, 4th is kk, 5th is kkW, 6th kkS. If it will search k and replace it, then it is not possible to search and replace correctly kk nor kkW nor kkS. There is strange numbering in ODT, args1043, args1029-1042, args1026-1023, args1019-1018, args1016-1017, args962 … Are these argsNumbers for proper order?
@KamilLanda I just reduced 43910 lines to 120 without changing the sequence of replacements. I did not have the patience to analyze the correctness of the code - I simply repeated the sequence of replacements from the original KrutiDevToUnicode
procedure. Yes, you’re right, it was necessary to at least pre-sort the table of replacements in descending order of string lengths…
This part will not work correctly if there is at least one "”k"
in the text. All 934 pairs should be checked for compatibility and for duplicates.
… and in this process, made it possible to grasp, analyze and fix problems in the code. It’s simply unmanageable with nearly 50 thousand lines.
This code works more than 95℅. But the problem in this code is it also converts the the text which is in English and which is not in kruti dev font. There are several kruti dev fonts like Kruti Dev 055, Kruti Dev 010 etc. I want the code should not disturb the English text. So I feel that if you select the text in kruti dev font and then run the macro and if the macro will affect only on the selected text it will be more useful.
Why? Why didn’t you put it in the body of your question? @Lupp was right
Also heed the advice of @Lupp
Yes, not the text with the code of your macro, but a sample of the transcoded text - this is necessary to check the correct operation of the code before publishing it.
Please carefully check this conversion table and make the necessary corrections (or confirm it is correct) - TrueType_To_Unichar.ods (51.4 KB)
This macro do not run on Tables in Writer and in Calc
This macro do not work in table and in calc.
After about 15 months you come back to this “solved” thread.
Unfortunately I don’t understand what you want to tell.
And there still is no TextDocument (.odt)
to help with a better understanding and for experiments. Or did I miss one?
I took the time (rather a lot of time) to analyse your huge recorded “macro” with the help of a spreadsheet, and found that you had recorded 934 replacements. You must have spent a full week of work with the project. Now you can tell us that the question is actually answerdd (“problem solved”). Otherwise you should add useful information and the mentioned example.
I marked it as solved just few days ago. My problem of more than 900 find and replacement not get solved. I solved nearabout 20-30 find and replace commands. I recorded the macro then used mail merge and with the help of mail merge I put those more than 900 find and replace texts. When I tried to find and replace with your solution my PC gets hanged. So I leave that problem and now I just want that the find and replace should work in tables and in calc.
Kruti Dev Find and Replace with Special Character.odt (23.7 KB)
Hallo
Its pretty simple with python
import re
rex = re.compile(r"yka|k")
def repl(match):
if match.group() == "yka":
return "लां"
else:
return "ष"
def replace_in_selections(*_):
doc = XSCRIPTCONTEXT.getDocument()
selections = doc.CurrentSelection
for selection in selections:
selection.String = rex.sub(repl, selection.String)
To organize and run python, you should install apso.oxt from here
@karolus Yes, you’re right, this approach is better than JeJe’s idea - why search for all available occurrences of the search string in the entire document, if we can just replace the strings in the selections? This works much faster:
Sub ReplaceInSelection
Dim OriginalStrings As Variant, TargetStrings As Variant
Dim oSelections As Variant, sText As String
Dim i As Long, k As Long
OriginalStrings = Array("yka", "k")
TargetStrings = Array("लां", "ष")
oSelections =ThisComponent.getCurrentSelection()
For k = 0 To oSelections.getCount()-1
sText = oSelections.getByIndex(k).getString()
For i = LBound(OriginalStrings) To UBound(OriginalStrings)
sText = Replace(sText,OriginalStrings(i),TargetStrings(i),1,-1,0)
Next i
oSelections.getByIndex(k).setString(sText)
Next k
End Sub
If you want to replace only the simple characters and you don’t need the regular expressions for finding, then it is possible to search the regular expression from searched characters and replace the found parts. The advantage is, it will keep up the formatting; and it can be faster than searching the selection again and again for every item in array.
I haven’t installed the fonts for your example yka, so the example for replacing is: bc → @1; op → #:. So the macro searches the (bc|op) and then replaces the found part bc or op.
I don’t know how large document you need to search, so I put there also the lockControllers (it could be faster), and Undo Manager for only one step in Undo (it could be more comfortable for mistake in replacing).
Edit the variable p() to your replacements.
find-repl-in-selection.odt (15.0 kB)
This isn’t quite correct. An inserted replacement always gets the attributes from the next position left of its start. If the finding getting replaced is not inside of an uniformly formatted text range there will be a change.
See attachment-in-return:
find_repl_in_selection_ReExcept.odt (16.6 KB)
To avoid his, you should firszt insert the replacement behind the finding, and annullated the found part subsequently. If the search string isn’t formatted uniformly at all, there isn’t an unambiguos requirement concerning the attributes to use for the replacement anyway.
I forgot this behavior :-).
Here is the fix, of course it supposes only one formatting for wanted items.
find_repl_in_selection_ReExcept-3.odt (17.0 kB)
I tried to make the multiformat F&R in past, but I still didn’t finish it.
Thanks a lot
My PC hangs if I put hundreds of items in the array.