rrandom Posted October 18, 2013 Share Posted October 18, 2013 Hello all. We run into problems, modifying a large amount of strings the following way: [1] should become <a href="footnotes.html#1">[1]</a> [2] should become <a href="footnotes.html#2">[2]</a> ... [570] should become <a href="footnotes.html#570">[570]</a> Thank you a lot for any kind of help, hint or advice rRaNDom Link to comment Share on other sites More sharing options...
mrflibblehat Posted October 18, 2013 Share Posted October 18, 2013 (edited) What seems to be the problem? If you are asking what I think you are asking, use a loop For $i = 1 to 570 ConsoleWrite('<a href="footnotes.html#' & $i & '">[' & $i & ']</a>' & @CRLF) Next or if its an array you are on about Local $vArr[571] For $i = 1 to Ubound($vArr) -1 $vArr[$i] = '<a href="footnotes.html#' & $i & '">[' & $i & ']</a>' ConsoleWrite('$vArr[' & $i & '] = ' & $vArr[$i] & @CRLF) Next Edited October 18, 2013 by mrflibblehat [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font] Link to comment Share on other sites More sharing options...
Malkey Posted October 18, 2013 Share Posted October 18, 2013 Another interpertation of the problem solved. Local $sString = "[1]" & @LF & "[2][3]" & @LF & "..." & @LF & "[570]" & @LF Local $sNewString = StringRegExpReplace($sString, "(\[)(\d+)(\])", '<a href="footnotes.html#\2">[\2]</a>') ConsoleWrite($sNewString & @LF) Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 Hello mrflibblehat, Thank you for your interest and your answer. The problem is, that the [n]s are text-parts in a very large html-document. We want to build up a search-replace function to modify all the parts in a single action. Greetings RrANdom Link to comment Share on other sites More sharing options...
mrflibblehat Posted October 18, 2013 Share Posted October 18, 2013 do you have a sample of the data we can work from? [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font] Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 (edited) Hello mrflibblehat and Malkey, as a sample I post some html source: (all.html) At this time, the footnotes are just named, but they should become linked to the footnotes document (as described above). Our idea is, that we open the doc. via an autoit.exe and let it modify the all.html in the desired way. Thank you for your interest and help rrANdoM ------------------------------------------ expandcollapse popup<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ev="http://www.w3.org/2001/xml-events"> <head> <title>Photobook</title> <link href="styles/style.css" rel="stylesheet" type="text/css"/> </head> <body> <div id="all.html" xml:lang="de-DE"> <div> <p class="bild_kap"><img class="b18" src="images/kapitelzeichen.jpg" alt="kapitelzeichen.jpg"/></p> <h1 id="all" class="kapitel-titel">Preface</h1> <p class="text-start">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. [1] Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. </p> <div class="group"><p class="bild"><img class="b100" src="images/002.jpg" alt="Foto"/></p> <p class="text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. [2] Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. </p> ...... <p class="text-start">In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.[570] Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. </p> </div> </div> </body> </html> Edited October 18, 2013 by rrandom Link to comment Share on other sites More sharing options...
l3ill Posted October 18, 2013 Share Posted October 18, 2013 (edited) I think I see what you are trying to do. The _ReplaceStringInFile is our friend when trying to find and replace ina file with AutoIT. Start with an input box FileOpenDialog to choose the file that needs to be modified. Good Luck. Bill Edited October 18, 2013 by billo My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 Thank you for all your ideas, but the needed point is missing. Sure we have to start with an open-dialog. #include <array.au3> #include <file.au3> Dim $aArray $ret = "" $filename = FileOpenDialog ("Open...", "", "HTML Documents (*html)") _FileReadToArray ($filename, $aArray) $file = FileOpen ($filename, 2) MISSING LINK ;) FileWrite ($file, $ret) FileClose ($file) Any further help would be very welcome. Best wishes rraNdoM Link to comment Share on other sites More sharing options...
l3ill Posted October 18, 2013 Share Posted October 18, 2013 Try Playing around with this and see if you can get it to do what you want: It works as is but only as a test. This is set up for 2 different find and replace searches, you can add more... #include <File.au3> Local $find = 'Photobook' Local $replace = 'Jakofasaures' Local $find_1 = 'styles' Local $replace_1 = 'Deedledooo' Local $filename = FileOpenDialog("Your File", @DesktopDir & "\", "", 1) If @error Then MsgBox(4096, "", "No File(s) chosen") EndIf Local $retval = _ReplaceStringInFile($filename, $find, $replace) If $retval = -1 Then MsgBox(0, "ERROR", "The pattern could not be replaced in file: " & $filename & " Error: " & @error) Exit Else MsgBox(0, "INFO", "Found " & $retval & " occurances of the pattern: " & $find & " in the file: " & $filename) EndIf Local $retval_1 = _ReplaceStringInFile($filename, $find_1, $replace_1) If $retval = -1 Then MsgBox(0, "ERROR", "The pattern could not be replaced in file: " & $filename & " Error: " & @error) Exit Else MsgBox(0, "INFO", "Found " & $retval_1 & " occurances of the pattern: " & $find_1 & " in the file: " & $filename) EndIf let me know if you have any trouble. viel spass ;-) Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 Thank you Bill, this part is the core, is the problem: Local $find = Local $replace = As we're designers, we're neither familar working with regular expression nor able to transfer that - not given - knowledge to variables (1-570 as mentioned). Thank you for wishing us »viel spass« but if I'm honest you should better wish us little tribulation ;[ We hoped that it's only a little problem for someone who is living with code; we don't want to go the hard way and do this job step by step. RrAndoM Link to comment Share on other sites More sharing options...
l3ill Posted October 18, 2013 Share Posted October 18, 2013 No Problem,, did you try the code? It is setup to run as is "as a test". Find = whatever you want to find Replace = what you want to replace it with If after running the code on your test.html you have a look at the variables or things you want changed and see that they are... well the rest is a matter of changing the code to your liking. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 Thank you! A short hint concerning working with the variables (1-570) would be great to start the adventure ... Best wishes rranDOm PS By the way: any additional help from others is still appriciated Link to comment Share on other sites More sharing options...
l3ill Posted October 18, 2013 Share Posted October 18, 2013 I get the hint ;-) Someone will be along shortly with a download link to your complied script. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 18, 2013 Moderators Solution Share Posted October 18, 2013 rrandom,Save the example HTML you posted above and then run this script on the file:#include <Constants.au3> $sData = FileRead("HTML.txt") $sNewData = StringRegExpReplace($sData, '\[(\d+)\]', '<a href="footnotes.html#$1">[$1]</a>') MsgBox($MB_SYSTEMMODAL, "New HTML", $sNewData)When I run it, all '[**]' are replaced by '<a href="footnotes.html#**">[**]</a>'. So there is no need for any loop - every instance is replaced regardless of the number inside. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rrandom Posted October 18, 2013 Author Share Posted October 18, 2013 Bill, Melba23 and the others, Thank you a lot for your kind and usefull help. Your help is saving us not only time! Best wishes RRandOm Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now