Search the Community
Showing results for tags 'replace'.
-
hello sirs i've some questions about StringRegExpReplace i hope you can help me i tried to make a function that give me the host of the url and other give me the url with out host for example i've this link https://www.example.com/vb/result.php i need the first give me the example.com and the other give me /vb/result.php i find that $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page) but i found some problems i need your help to correct it first: when i get the host if the url has www i want to remove it second: if the url with out host did not have other things i need the result to be "" e.g https://www.example.com the first i want it example.com and the second i want it to be "" i hope that you can help me thanks in advance
- 15 replies
-
- stringregexpreplace
- replace
-
(and 2 more)
Tagged with:
-
So basically need to pull text from a .txt file or .sql and use that text to replace something within a different file. First File: jumps Or: Text1 = jumps Text2 = fence Second File: My Dog XXXXX over the YYYYY. After Script: My Dog jumps over the fence I have found a good start, I'm basic programmer at best, I have some experience but this gets out of my wheel house. Any help is appreciated.
- 13 replies
-
Hello, Either drag drop the opened file on the server and the temp file, Aut2Exe could not copy to the destination file, as that one is opened, to the edits of this GUI, or take the Aut2Exe error message line to your clipboard, the line will be split automatically. This script does not check For the required rights to the destination folder (to close open file handles) for correct input Use either clipboard (Aut2Exe message), drag & drop, or copy the full paths of source and destination file *IN ONE* (don't type, if you want to do so, modify the script, for me it's fine this way ;-) Example Error Message: !>11:19:15 Problem copying file from: C:\Users\UserName\AppData\Local\AutoIt v3\Aut2exe\~AU98E6.tmp.exe To :z:\MyAutoitExeForTheUsers.exe #include <GUIConstantsEx.au3> #include <NetShare.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <EditConstants.au3> ; Enumerate open files on the server $DragDropOpenFile = "<drag drop the opened file on a server share here>" $DragDropNewFile = "<drag drop the file supposed to replace the above one here>" $NewFile = "" $Gui_h = 250 $Gui_w = 800 $vDist = 7 ; GUICreate($GuiTitle, $w, $h, @DesktopWidth - $w - 100, @DesktopHeight - $h - 60, -1, $WS_EX_ACCEPTFILES) ; generally enable drag-drop for files into other GUI controls $myGui = GUICreate("Tool to forcibly close & replace open files on server shares", $Gui_w, $Gui_h, 100, 100, -1, $WS_EX_ACCEPTFILES) $InputFileToClose = GUICtrlCreateInput($DragDropOpenFile, 20, $vDist, $Gui_w - 40, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; allow drag-droping files for this control, $InputFile Opt("Guicoordmode", 2) $InputFileNew = GUICtrlCreateInput($DragDropNewFile, -1, $vDist) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; allow drag-droping files for this control, $InputFile GUICtrlSetState(-1, $GUI_DISABLE) $lServer = GUICtrlCreateLabel("<server>", -1, $vDist) $lShare = GUICtrlCreateLabel("<share-mapping>", -1, $vDist) $lPath = GUICtrlCreateLabel("<sub-path>", -1, $vDist) $lFile = GUICtrlCreateLabel("<file>", -1, $vDist) $doit = GUICtrlCreateButton("Search and close for open file handles", -1, $vDist) GUICtrlSetState(-1, $GUI_DISABLE) $exit = GUICtrlCreateButton("Cancel", -1, $vDist) GUISetState() $FN = False $FNnew = "" $FNmatch = False $ToolTitle = "" $ToolTxt = "" $RegExA2E = "(?i)^(?:.*?Problem copying file from: )(.*?)(?: To :)(.*$)" ; $1 = compiled local TEMP file, $2 = not replacable destination file ; Examle Replacement failed output: !>11:19:15 Problem copying file from: C:\Users\USERNAME\AppData\Local\AutoIt v3\Aut2exe\~AU98E6.tmp.exe To :z:\MyAutoitExeForTheUsers.exe While 1 $Clip = ClipGet() If StringRegExp($Clip, $RegExA2E) Then $Src = StringRegExpReplace($Clip, $RegExA2E, "$2") GUICtrlSetData($InputFileToClose, $Src) $Dst = StringRegExpReplace($Clip, $RegExA2E, "$1") GUICtrlSetData($InputFileNew, $Dst) EndIf $input = GUICtrlRead($InputFileToClose) If $input <> $DragDropOpenFile Then ; da wurde was reingezogen $DragDropOpenFile = $input If StringLeft($input, 2) = "\\" Then $Type = "UNC" $ServerShareUNC = StringLeft($input, StringInStr($input, "\", 0, 4) - 1) $fRelPathFN = StringReplace($input, $ServerShareUNC, "") $fPath = StringLeft($fRelPathFN, StringInStr($fRelPathFN, "\", 0, -1)) $FN = StringTrimLeft($fRelPathFN, StringInStr($fRelPathFN, "\", 0, -1)) ElseIf StringMid($input, 2, 1) = ":" Then ; Pfad mit Laufwerksbuchstabe, evtl. Netzwerk Mapping (erforderlich) $drive = StringLeft($input, 2) $Type = DriveGetType($drive) If $Type = "Network" Then $ServerShareUNC = DriveMapGet($drive) $foo = StringReplace($input, $drive, $ServerShareUNC) ; Laufwerkspfad in UNC Pfad umwandeln $fRelPathFN = StringReplace($foo, $ServerShareUNC, "") $fPath = StringLeft($fRelPathFN, StringInStr($fRelPathFN, "\", 0, -1)) $FN = StringTrimLeft($fRelPathFN, StringInStr($fRelPathFN, "\", 0, -1)) Else MsgBox(48, @ScriptLineNumber, "This script can *ONLY* close remotely handles for files open on server shares!" & @CRLF & _ $input & @CRLF & _ $drive & " = " & $Type) ContinueLoop 2 EndIf EndIf $Server = StringLeft($ServerShareUNC, StringInStr($ServerShareUNC, "\", 0, 3) - 1) $Share = StringTrimLeft($ServerShareUNC, StringInStr($ServerShareUNC, "\", 0, 3) - 1) GUICtrlSetData($lServer,"Server = '" & $Server& "'") GUICtrlSetData($lShare, "Mapping = '" & $Share & "'") GUICtrlSetData($lPath, "SubPath = '" &$fPath & "'") GUICtrlSetData($lFile, "FileName= '" & $FN &"'") GUICtrlSetState($doit, $GUI_ENABLE) GUICtrlSetState($InputFileNew, $GUI_ENABLE) EndIf If $NewFile <> GUICtrlRead($InputFileNew) Then $NewFile = GUICtrlRead($InputFileNew) If $NewFile <> $DragDropNewFile Then If StringInStr($NewFile, $DragDropNewFile) Then $NewFile = StringReplace($NewFile, $DragDropNewFile, "") GUICtrlSetData($InputFileNew, $NewFile) EndIf $FNnew = StringTrimLeft($NewFile, StringInStr($NewFile, "\", 0, -1)) If $FN = $FNnew Then If $FNmatch = False Then $FNmatch = True GUICtrlSetData($doit, "Search for & Close open file handles, then replace file") EndIf Else If $FNmatch Then $FNmatch = False GUICtrlSetData($doit, "Search for & Close open file handles, then replace file") GUICtrlSetData($InputFileNew, $DragDropNewFile) EndIf EndIf EndIf EndIf Switch GUIGetMsg() Case $exit, $GUI_EVENT_CLOSE GUIDelete($myGui) Exit Case $doit AbArbeiten($Server, $Share, $fPath, $FN) EndSwitch WEnd Func AbArbeiten($_Srv, $_Shr, $_fPth, $_fNme) Local $iID = 0 Local $iRights = 1 Local $iLckCount = 2 Local $iFPFN = 3 Local $iUser = 4 ConsoleWrite($_fPth & $_fNme & @CRLF) Local $aFile = _Net_Share_FileEnum($_Srv) If IsArray($aFile) Then ; _ArrayDisplay($aFile) Local $x $ToolTxt = "Open File Handles:" $ToolTitle = "Handles to be checked total: " & $aFile[0][0] UpdateToolTip() AdlibRegister(UpdateToolTip, 1000) For $x = $aFile[0][0] To 1 Step -1 $ToolTitle = $x & " handles remaining for checking..." If Not StringInStr($aFile[$x][$iFPFN], $_fPth & $_fNme) Then ; ConsoleWrite("Nix Enthalten in: " & $aFile[$x][$iFPFN] & @CRLF) _ArrayDelete($aFile, $x) Else $ToolTxt &= @CRLF & $aFile[$x][$iFPFN] & ", User = " & $aFile[$x][$iUser] ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToolTxt = ' & $ToolTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndIf Next $aFile[0][0] = UBound($aFile) - 1 _ArraySort($aFile, 0, 1, 0, $iUser) ; _ArrayDisplay($aFile, $aFile[0][0] & " FileLocks found.") If $aFile[0][0] = 0 Then $ToolTitle = "Done, no open file handles were found" $ToolTxt &= @CRLF & ", no handles to be closed for this file!" Sleep(2000) $ToolTxt = "" ReplaceFile() Else $ToolTitle = $aFile[0][0] & " open file handles were found..." $CloseErr = 0 For $x = 1 To $aFile[0][0] If _Net_Share_FileClose($Server, $aFile[$x][$iID]) Then $ToolTxt &= @CRLF & @TAB & "Handle closed: " & $aFile[$x][$iID] Else $ToolTxt &= @CRLF & "ERROR: Handle Close Failed! --> " & $aFile[$x][$iFPFN] & ", User = " & $aFile[$x][$iUser] $CloseErr += 1 EndIf Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CloseErr = ' & $CloseErr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console If $CloseErr = 0 Then $ToolTitle = "All found open file handles could be closed." ReplaceFile() Else $ToolTitle = $CloseErr & " Handles could *NOT* be closed!" Sleep(2000) EndIf Sleep(1000) $ToolTxt = "" $ToolTitle = "" EndIf Else MsgBox(0, "not an array", $aFile & @CRLF & @error & @CRLF & @extended & @CRLF & _ "Unable to retrieve the array of open file handles for " & $Share) EndIf EndFunc ;==>AbArbeiten Func UpdateToolTip() ToolTip($ToolTxt, MouseGetPos(0) + 20, MouseGetPos(1) + 20, $ToolTitle) ; ConsoleWrite( $ToolTxt & @CRLF & $ToolTitle & @CRLF & "-------------------" & @CRLF) EndFunc ;==>UpdateToolTip Func ReplaceFile() If FileExists($NewFile) Then If FileCopy($NewFile, $input, 1 + 8) Then $ToolTitle = "File successfully replaced." $ToolTxt = "Done" Else $ToolTitle = "File could *NOT* be replaced." $ToolTxt = "Possibly another open file handle spawned while this script was running." & @CRLF & _ "Simply start over again, please." MsgBox(48, $ToolTitle, $ToolTxt) EndIf EndIf EndFunc ;==>ReplaceFile
-
- locked open file
- handle
-
(and 3 more)
Tagged with:
-
replace a particular text in a file - (Moved)
Rskm posted a topic in AutoIt General Help and Support
Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()). WERIS WWWJP 3.83 8.330 1.000 1097.RAXX The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999) please put ur suggestions -
Good evening everyone I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace(). The replace does work everywhere in the document, but, it does not work in Headers or Footers. Am I missing something or am I forced to use the code below? I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers. Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance Best Regards.
-
Hi All, I'd like to replace 'COMMA' with ',' for example: $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', ',') Now I've tried escaping the ',' in various ways unsuccessfully, such as: '[,]' "[,]" '\,' [,] seems to work in the pattern, I just can't figure out how to use it in the replace, and it seems everyone online is only interested in removing/replacing commas lol. I also tried creating and using a variable as the replacement but also didn't work: $myComma = "," $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', $myComma) I'm sure it's super simple if someone could point me in the right direction - thanks.
-
i need a script that can replace words in text with other words from a words list it has to have 2 edit boxes input/output and a button "run" from word_list.txt it choses which word to replace with. words are separated with commas for multiple choice ; AutoIt GUI Example ; Created: 17/01/2005 - CyberSlug ; Modifed: 05/12/2011 - guinness ; Modifed: 09/06/2014 - mLipok #Region INCLUDE #include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #EndRegion INCLUDE #Region GUI GUICreate("Sample GUI", 400, 420) GUISetIcon(@SystemDir & "\mspaint.exe", 0) #EndRegion GUI #Region EDIT GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 10, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT #Region EDIT2 GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 185, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT2 #Region BUTTON GUICtrlCreateButton("Sample Button", 10, 360, 100, 30) GUICtrlSetTip(-1, '#Region BUTTON') #EndRegion BUTTON #Region GUI MESSAGE LOOP GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() #EndRegion GUI MESSAGE LOOP
-
input a word and replace its letters as output
way1000 posted a topic in AutoIt GUI Help and Support
i'm trying to create a program that let's the user type a word in an input field (gui) and when a button is pressed the letters of the word are replaced by 1 word each from a list of words in a text file i created the gui for it but i need help to add some more code to make it work like intented each letter of a word should be replaced by a word from a text file the text file is a source for replacing letters is a file with 2 columns separated by tab that contains the entire alphabet (26 rows) please help if possible i posted an example gui screenshot -
I am currently doing a project involving keeping some parameters in an internal 2d array. I am reading part of that to and from an ini file. As part of the reading I need to put the variables from the ini file into the 2D array. I have found _arrayinsert(), but that creates additional lines. Bascially I would like something as this: Original array: [1] a1 a2 a3 a4 [2] b1 b2 b3 b4 [3] c1 c2 c3 c4And reading setting for "2" being d1 d2 d3 d4 I should now have [1] a1 a2 a3 a4 [2] d1 d2 d3 d4 [3] c1 c2 c3 c4Is there a built-in UDF or similar to do something like that already ? Or did I missing something real obvious ? I have rolled my own code, which works. But of course it could be improved. Thanks for all comments, happy to learn from you all !
-
Hallo forum members, I am looking for a pattern to replace user= and password= between double quotes user="Alfa75" becomes user="*****" password="xstsgSvs" becomes password="*****" In my example the opposite happens, username and password is still visable StringReplace or StringRegExpReplace is not my best skill Opt("MustDeclareVars", 1) Global $Config = @ScriptDir & "\config.xml" _Config() Func _Config() If FileExists($Config) Then Local $file = FileOpen($Config, 0) Local $sData = FileRead($file) FileClose($file) Local $rData = StringRegExpReplace($sData, "(user=Chr(34)).+?(password=Chr(34)", "\1") ;$rData = StringReplace($rData, "user=", "*****") ; <-- desired with asterisk ;$rData = StringReplace($rData, "password=", "*****") ; <-- desired with asterisk $rData = StringReplace($rData, "user=", "") $rData = StringReplace($rData, "password=", "") MsgBox(0, "config.xml : ", $rData) ;ClipPut($rData) Else MsgBox(0, "config.xml : ", "Not found") EndIf EndFunc config.xml <config> <line short="LT" city="ASD" user="Alfa75" password="xstsgSvs" code="020" registered="1" period="20" /> <line short="IC" city="RTD" user="Jonh09" password="Gdte55567" code="010" registered="1" period="25" /> <line short="IB" city="UT" user="2ronals" password="B776656" code="030" registered="0" period="15" /> <line short="IC" city="RTD" user="DEjong67" password="=0gdd++00L==" code="010" registered="1" period="25" /> <line short="ST" city="AML" user="Eddy03" password=".te555=77Ai" code="036" registered="1" period="25" /> <line short="LT" city="CAS" user="BassB" password="+gdtWU=" code="0251" registered="1" period="35" /> <line short="IC" city="DT" user="lian033" password="77t--e55+=" code="015" registered="1" period="45" /> </config> desired result <config> <line short="LT" city="ASD" user="*****" password="*****" code="020" registered="1" period="20" /> <line short="IC" city="RTD" user="*****" password="*****" code="010" registered="1" period="25" /> <line short="IB" city="UT" user="*****" password="*****" code="030" registered="0" period="15" /> <line short="IC" city="RTD" user="*****" password="*****" code="010" registered="1" period="25" /> <line short="ST" city="AML" user="*****" password="*****" code="036" registered="1" period="25" /> <line short="LT" city="CAS" user="*****" password="*****" code="0251" registered="1" period="35" /> <line short="IC" city="DT" user="*****" password="*****" code="015" registered="1" period="45" /> </config>
- 8 replies
-
- double quotes
- asterisk
-
(and 1 more)
Tagged with:
-
Func __ReplaceStringInFile($szFileName, $szSearchString, $szReplaceString, $fCaseness = 0, $fOccurance = 1) Local $iRetVal = 0 Local $nCount, $sEndsWith ; Check if file is readonly .. If StringInStr(FileGetAttrib($szFileName), "R") Then Return SetError(6, 0, -1) ;=============================================================================== ;== Read the file into an array ;=============================================================================== Local $hFile = FileOpen($szFileName, $FO_READ) If $hFile = -1 Then Return SetError(1, 0, -1) Local $s_TotFile = FileRead($hFile, FileGetSize($szFileName)) If StringRight($s_TotFile, 2) = @CRLF Then $sEndsWith = @CRLF ElseIf StringRight($s_TotFile, 1) = @CR Then $sEndsWith = @CR ElseIf StringRight($s_TotFile, 1) = @LF Then $sEndsWith = @LF Else $sEndsWith = "" EndIf Local $aFileLines = StringSplit(StringStripCR($s_TotFile), @LF) FileClose($hFile) ;=============================================================================== ;== Open the output file in write mode ;=============================================================================== Local $iEncoding = FileGetEncoding($szFileName) Local $hWriteHandle = FileOpen($szFileName, $iEncoding + $FO_OVERWRITE) If $hWriteHandle = -1 Then Return SetError(2, 0, -1) ;=============================================================================== ;== Loop through the array and search for $szSearchString ;=============================================================================== For $nCount = 1 To $aFileLines[0] If StringInStr($aFileLines[$nCount], $szSearchString, $fCaseness) Then $iRetVal = $iRetVal + 1 If $fOccurance = $iRetVal Then $aFileLines[$nCount] = StringReplace($aFileLines[$nCount], $szSearchString, $szReplaceString, 1 - $fOccurance, $fCaseness) ExitLoop EndIf EndIf Next ;=============================================================================== ;== Write the lines back to original file. ;=============================================================================== FileClose($hWriteHandle) Local $Tempfile = _TempFile() FileWrite($Tempfile, _ArrayToString($aFileLines, @LF, 1)) FileMove($Tempfile, $szFileName, 1) Return $iRetVal EndFunc ;==>__ReplaceStringInFile Yes, I know guinness improved the ReplaceStringInFile function in terms of speed and efficiency but hear me out. I made some changes to the original myself that increased the speed of the writing and more importantly for me change the occurrence option so the function would only replace that specific occurrence of string. I not saying use my code. What I am suggesting is to add extra functionally to the ReplaceStringInFile so there is a option to replace a specific occurrence. I could not think of a way to do this with the new one guinness made so above is just an example of how I did it with the old one. I have also attached the file.au3 file. File.au3
-
Hi, I know there are many threads on this argument, but i'm searching the fastest method to replace some text in a file: Local $hFile = "Test.txt" $sData = "FIRSTNAME Lastname - BAT _ TIME1" & @CRLF & _ "FIRSTNAME Lastname - BAT _ TIME2" & @CRLF & _ "FIRSTNAME Lastname - BAT _ TIME3" FileWrite($hFile, $sData) FileClose($hFile) $hFileOpen = FileOpen($hFile) $ReadData = FileRead($hFileOpen) $sNewFile = StringRegExpReplace($ReadData, '(?i:' & "TIME" & ')', "COOL") ;~ $sNewFile = StringRegExpReplace($sData, "(-)(.*)(_)", "Another Text") FileClose($hFile) FileOpen($hFile, 2) FileWrite($hFile, $sNewFile) FileClose($hFile) 1) This is the fastest method, using StringRegExpReplace? 2) How to combine 2 or more StringRegExpReplace with different pattern ( i'm totally new to this )? Thanks
-
Hi everyone I have 2 basic question about hex editing - I have several texts with a common problem, in stead of having CRLF (carriage return+line feed) only had 0x0A (LF), how do I add 0D behind every 0x0A? - Its possible to edit only the beginning of a file (speaking in large files that should't be loaded in memory) and save the changes?
-
Hi, i found several examples and also some UDF's, but they didnt helped me really well. Can someone give me an broad hint, how to automate the following neccessary process in a word file thorugh an AutoIT script? find all places/strings which have the (font.color grey25% or grey50%) and are striken through and make it hidden (FontEffectsHidden Text) find all places/strings which are in font.color red and change their font.color into black Thanks...