Jump to content

Search the Community

Showing results for tags 'stringreplace'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 15 results

  1. As for the object, in this case the StringReplace() function does not work for me. These are my steps: 1) Extract the subject from an EML file. (the first character is an emoji ) source from EML file: $sSubject = "?utf-8?B?8J+TiCA1IG9mIHRoZSBCZXN0IFN0b2NrcyB0byBCdXkgZm9yIERlY2VtYmVy?=" 2) in this case I perform a decoding with _QuotedPrintable_DecodeEncodedWord() output is: $sSubject = "?? 5 of the Best Stocks to Buy for December" 3) I perform StringReplace(): $sSubject = StringReplace($sSubject, "??", "") or $sSubject = StringReplace($sSubject, Chr(63)&Chr(63), "") But the characters ?? they are not replaced. Yet if I make an Asc of every character of the string with a for loop, are the first two characters really? that is 63 For cycle         Local $aArray = StringSplit($sSubject, "", $STR_NOCOUNT)         For $i = 0 To UBound($aArray)-1             ConsoleWrite($aArray[$i] & " - " & Asc($aArray[$i])& @CR)         Next Output: ? - 63 ? - 63 - 32 5 - 53 - 32 o - 111 f - 102 - 32 t - 116 h - 104 e - 101 - 32 Does anyone have an explanation of why it doesn't work? Thank you all
  2. I am adding labour charge to total paid amount using : #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData3 = _IETableWriteToArray ($oTable) Local $sitem1 = $aTableData3[5][1] Local $sitem2 = $aTableData3[5][2] Local $lcharge = "10" ;add manualy using inputbox, becuase not generating online Local $atotPric = "Payable Total Price " Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.Innertext = $atotPric Then $iatotPric = $oTd.NextElementSibling.innertext MsgBox (0, "2", $iatotPric) EndIf Next $irCtotal = StringFormat("%.2f", $sitem1 + $sitem2 + $lcharge) $crTotp = StringReplace(_IEBodyReadHTML($oIE), $iatotPric, $irCtotal) _IEBodyWriteHTML ($oIE, $crTotp) But, It was also changing Total price, I want to change only Payable Total Price.
  3. Default keyword for optional parameter is interpreted wrongly. ConsoleWrite(StringReplace("aa", "a", "b", Default, 1) & @CRLF) StringReplace ( "string", "searchstring/start", "replacestring" [, occurrence = 0 [, casesense = 0]] ) The code above will output ab even thou the default value for the occurrence is 0 (replace all). Of course using zero instead of Default will work fine.
  4. Hi All, I have written a UDF for one of my requirement which replaces a single character in string with a sub string/another character. I am using this for my requirement by calling below function as StrReplace("C:\Software\Autoit\Substr","\","\\") and gives result as C:\\Software\\Autoit\\Substr Please let me know if this can be improvised or any mistakes to correct. ;=============================================================================== ; ; Function Name: StrReplace($INPUT_STRING) ; Description: This function is to replace a character with another in a string. ; Parameter(s): $INPUT_STRING - Original String Value ; $STR_2_FIND - Single Character to find the $INPUT_STRING ; $STR_2_REPLACE - Substring/Multiple Characters to replace in place of $STR_2_FIND value ; Requirement(s): Replacing one single Character in a string with multiple Characters ; Return Value(s): success - Output string after replacing a character with required character ; failure - 0 ; Author(s): smartkey ; ;=============================================================================== Func StrReplace($INPUT_STRING, $STR_2_FIND, $STR_2_REPLACE) Local $OUTPUT_STRING = "" If StringLen($INPUT_STRING) > 0 Then If StringMid($INPUT_STRING,1,1) = $STR_2_FIND Then $OUTPUT_STRING = $OUTPUT_STRING & $STR_2_REPLACE Else $OUTPUT_STRING = StringMid($INPUT_STRING,1,1) EndIf For $i=2 to StringLen($INPUT_STRING) If StringMid($INPUT_STRING,$i,1) = $STR_2_FIND Then $OUTPUT_STRING= $OUTPUT_STRING & $STR_2_REPLACE Else $OUTPUT_STRING= $OUTPUT_STRING & StringMid($INPUT_STRING,$i,1) EndIf Next Return $OUTPUT_STRING Else Return 0 EndIf EndFunc
  5. Hi! I have another problem with AutoIT. You see, I'm still the one who's just starting out with this great programming language. I have a problem with AutoIT, it seems not to recognize the "StringReplace" function even when it is by default. The code was made half in KODA and half of my own. It is a software programmed for the Italian language (I am Italian) and translate the SMS language into Italian correct. Would you help me? Thanks in advance. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $hull = "hello" StringReplace($hull, "hello", "hellx") $Form1 = GUICreate("Linguaggio SMS A Italiano", 507, 498, 192, 124) $Edit1 = GUICtrlCreateEdit("", 24, 40, 465, 177) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Inserisci qui il testo che non riesci a capire:", 24, 8, 205, 17) $Label2 = GUICtrlCreateLabel("Ecco il testo tradotto(non toccare questo campo):", 27, 237, 237, 17) $Edit2 = GUICtrlCreateEdit("", 24, 264, 465, 137) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Traduci", 104, 424, 249, 49) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 StringReplace(GUICtrlGetData($Label1), "qlc", "qualcuno") StringReplace(GUICtrlGetData($Label1), "qls", "qualcosa") StringReplace(GUICtrlGetData($Label1), "ke", "che") StringReplace(GUICtrlGetData($Label1), "x", "per") StringReplace(GUICtrlGetData($Label1), "pls", "per favore") StringReplace(GUICtrlGetData($Label1), "tu6", "tu sei") StringReplace(GUICtrlGetData($Label1), "zzz", "mi fai dormire") StringReplace(GUICtrlGetData($Label1), "hagn", "Buonanotte") StringReplace(GUICtrlGetData($Label1), "tvtb", "Ti voglio tanto bene") StringReplace(GUICtrlGetData($Label1), "tat", "Ti amo tanto") StringReplace(GUICtrlGetData($Label1), "lafs", "Amore a prima vista") StringReplace(GUICtrlGetData($Label1), "fli?", "Flirtiamo?") StringReplace(GUICtrlGetData($Label1), "msidt", "Mi sono innamorato di te") StringReplace(GUICtrlGetData($Label1), "ba", "Bacio") StringReplace(GUICtrlGetData($Label1), "midi", "Mi dispiace.") StringReplace(GUICtrlGetData($Label1), "ntm", "Non ti merito") StringReplace(GUICtrlGetData($Label1), "tdp", "Togliti dai piedi.") StringReplace(GUICtrlGetData($Label1), "amò", "Amore") StringReplace(GUICtrlGetData($Label1), "ap", "A presto!") StringReplace(GUICtrlGetData($Label1), "cmq", "comunque") StringReplace(GUICtrlGetData($Label1), "cvd", "Ci vediamo dopo") StringReplace(GUICtrlGetData($Label1), "Tvb", "Ti voglio bene") StringReplace(GUICtrlGetData($Label1), "nn", "non") StringReplace(GUICtrlGetData($Label1), "risp", "rispondimi") StringReplace(GUICtrlGetData($Label1), "cel", "cellulare") StringReplace(GUICtrlGetData($Label1), "dom", "qualcosa") StringReplace(GUICtrlGetData($Label1), "nm", "numero") StringReplace(GUICtrlGetData($Label1), "fv", "favore") StringReplace(GUICtrlGetData($Label1), "-male", "meno male") StringReplace(GUICtrlGetData($Label1), "disc", "discoteca") StringReplace(GUICtrlGetData($Label1), "se#", "settimana") StringReplace(GUICtrlGetData($Label1), "+ o -", "più o meno") StringReplace(GUICtrlGetData($Label1), "ts", "torno subito") StringReplace(GUICtrlGetData($Label1), "tvtbcoa", "Ti voglio tanto bene come amica") EndSwitch WEnd
  6. Junior Programmer here... Not much experience with opening, changing and closing files. I am trying to replace strings in a Text file except StringReplace does not actually replace the text. Here is a sample of my code... #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Local $iStrReturn = 0 Local $hFile Local $sText Local $sNewText ; Location of File to be read $sFileName = "C:\Temp\MyPlayer.exe.config" ; The default is FALSE. We want to change this to TRUE $bLoopChecked = True CheckBox() Func Checkbox() $hFile = FileOpen($sFileName,$FO_READ) ; Open file in read mode to get text If $hFile = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when Opening the file.") Exit EndIf FileSetPos($hFile, 0, 0) ; No idea if I need to do this, grasping at straws $sText = FileRead($hFile) ; Read the file into $sText If $sText = 1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading/writing the file.") Exit Else FileClose($hFile) ; Finished reading the file into $sText, so close the file. FileFlush($hFile) ; Manual says to use FileFlush between File Close and Open so here it is EndIf MsgBox(0,"Before Replacement",$sText) ; Displays the text read from the file to make sure something is there. ; Loop Check If $bLoopChecked = True Then ; Find the string return > 0 for success $iStrReturn = StringInStr('"<add key="LoopCheckbox" value=""False" />"', "False") ;MsgBox(0,"", "LoopCheckBox is " & $iStrReturn) If $iStrReturn > 0 Then ; If StringInStr returned > 0 the it found the string! ; The Meat of the code. This is where we have to replace "False" with "True" $sNewText = StringReplace($sText, '"<add key="LoopCheckbox" value="False" />"', '"<add key="LoopCheckbox" value="True" />"') MsgBox(0,"After Replacement",$sNewText) ; Display the text to see if it worked. $hFile = FileOpen($sFileName,$FO_OVERWRITE) ; Reopen the file to write to it, overwriting everything. FileWrite($hFile,$sNewText) ; Write the text to the file FileClose($hFile) ; Close the file EndIf EndIf EndFunc This is the file I am reading... <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> </startup> <appSettings> <add key="LoopCheckbox" value="false"/> </appSettings> </configuration> I tried opening the file with $FO_UTF8 and $FO_UTF8_NOBOM but got errors opening the file. The MsgBox "After Replacement" shows the value is still false.
  7. Hello hello! As the title suggests, I am fairly new to AutoIt. In fact, I am new to scripting/coding in general! I've done a few Codecademy courses on CSS and HTML and perhaps Java though this was all a few years back. I've recently come across AutoIt and decided to give it a try since I do quite a few repetitive tasks on a daily basis. In the last couple of weeks I've managed to master (or at least get comfortable with) mouse clicks(left/right), window focus, sending key strokes, controls, and pixel search. Now let's get to the topic. At this point in time I've tried out a few simple IE scripts but I am having difficulty understanding some things and tying everything together into one tool. Specifically, I am struggling with this little bit of code I got from DaleHohm in his IE examples thread. Post #3 (The last example.) #include <IE.au3> $sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not) $sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images $oIE = _IECreate() _IENavigate($oIE, $sWebPage) $oIMGs = _IETagNameGetCollection($oIE.document, "img") ; Loop through all IMG tags and save file to local directory using INetGet For $oIMG in $oIMGs $sImgUrl = $oIMG.src $sImgFileName = $oIMG.nameProp INetGet($sImgUrl, $sImgDir & $sImgFileName) Next I have a couple questions about the code above. 1) ".src" ".nameProp" What are these called? I figured out that I can change the .src to something like .href and it gets anything on the webpage with a .href tag but where can I learn more about these? I still haven't been able to figure out what ".nameProp" is for or what it does. Is there any documentation/list of all the different ".PurpleTextAfterAVariable" (Edit: Not sure why it's red in the above example, just checked SciTE and it's purple there) that I can use? 2) I understand that the code above gets every "For $oIMG in $oIMGs" on the page but how can I make it only get the first 5? I've tried doing a "count" and a "for" but I am unsure what to replace the "For...in" statement with to keep the script functional. Is there a way to limit the _IETagNameGetCollection function to only get a specific amount of tags? Finally, the reason I can't just use the code as is. The site I am trying to get images from works in this way: A href= "Link-To-Picture.jpg" Img src= "Link-To-Picture-thumbnail.jpg" The script above downloads every single thumbnail from the image gallery which is great, it does what it's supposed to but I need the full resolution image. After changing the script to get anything with an "A href" tag it does what I need it to do, it gets every single image in full resolution... along with every single one of the 80-100 extra files/links to other sites that are listed under an "A href" tag. Now I've come up with two solutions but unfortunately, as I mentioned above. I don't know how to put my solution into the code above to make it work. Solution 1) Only get the first 5 instances of "A href" on the page. As mentioned above. I don't know how to do this. Solution 2) Read the entire page, find "-Thumbnail.jpg" replace with ".jpg" and use the script as is. I understand how to do a replace. All I am missing is how to do a replace within a field in the code of an IE page. I assume that I have to use the HTMLRead functions but how do I use/alter the data read? I really hope all of this make sense and that someone here will be able to help me figure out a solution to my issue or at least answer one of my questions! I do have plenty more questions and I am sure that I'll have even more by the time I figure this out. Thank you very much for your time!
  8. Hello, I try to pull some data from a webpage. I need the value of local currency compared to the euro. I can go and open the required API page on the required date interval, read in from elsewhere, its format in the memory of the script is like this: 20161005 so YYYYMMDD. The return string if I try to view the opened API's source code is simple, but if I use _IEBodyReadHTML, _IEDocReadHTML, _IEBodyReadText i get it back with a lot of html code (i guess, it looks like HTML, and one of them doesn't show any string in the MsgBox when I try to chechk it) about its color etc. I need dates and the corresponding currency exchange rates (these can be found between <kozep>exchangerate</kozep>, but I need the first only after every month because the second is the avarage exchange rate of the month (i guessed this again). Now I have an approach which will work evantually I guess, but I'm pretty sure its not the standard aproach or how the creators of autoit envisiond the useage of their functions So I post my code here hoping, someone tells me how to do this simply and inteligently. Sorry for such question but I only used regex for much, much simplier tasks. My approach is to identify everything I dont need basicly, after getting rid of a few key problematic chars (like " ) and do this untill I'm only left with what I need. THe problem with this if anything change in the envierment the script has like 99,9999% chance to not run properly, and I would like to handle this better, even if APIs usually don't change that much according to my knowladge. Also I write this in a separat function for now, I will plan to call it from my other function which does different things with the corresponding excel files, among them is the calculation of local currency values of the bills with data from MNB (Hungarian National Bank or something) Here is my code so far, and what its gives back, I will update this with the pic from the source code I see from internet explorer and the webpage I see. Thank you for your help and insight! Func InternetRead() ;Create the URL for napiarfolyam API #cs http://api.napiarfolyam.hu/?bank=mnb&valuta=eur&datum=20160901&datumend=20160926 </penznem> után jön a használt árfolyam Példa Return: <item> <bank>mnb</bank> <datum>2016-09-06 11:25:18</datum> <penznem>EUR</penznem> <kozep>309.8500</kozep> <kozep>310.1700</kozep> </item> #ce ;Global $MinTime ;20160601000000 these are example variables I read in, during the function that will call this one ;Global $MaxTime ;20160610000000 Local $URLbase = "http://api.napiarfolyam.hu/?bank=mnb&valuta=eur" ;view-source: ;Local $MinTimeFormated = StringTrimRight($MinTime, 6) ;Local $MaxTimeFormated = StringTrimRight($MaxTime, 6) Local $URL = $URLbase & ("&datum=" & "20160601" & "&datumend=" & "20160603" & "") ;20160603 $MinTimeFormated, $MaxTimeFormated MsgBox(64, "Értesítés", "URL:" & $URL & "") Local $oIE = _IECreate($URL) Sleep(1000) Local $sHTML = _IEDocReadHTML($oIE) ;_IEBodyReadHTML - Is string but, MsgBox shows nothing ;_IEDocReadHTML - at least retunrs something (extra then what i see from thw source code, ctrl+u) ;_IEBodyReadText - at least retunrs something (extra then what i see from thw source code, ctrl+u) $sHTML = String($sHTML) If IsString($sHTML) Then MsgBox(64, "HTML String?", "The variable is a string") Else MsgBox(64, "HTML String?", "The variable is not a string") EndIf ;Variable is a String! ;StringSplit ;">datum</span>&gt;</a>" & "20160601" Local $Stuff = Chr(34) ;The " char ;Local $Stuff2 = "<a xmlns=http://www.w3.org/1999/xhtml class=collapse style=color: blue; marginleft: 2em; position: relative; href=#>&lt;<span style=color: rgb(153,0,0);>" Local $StringInput = $sHTML Local $sHTML = StringRegExpReplace($StringInput, "[-]", "") Local $StringInput = $sHTML Local $sHTML = StringStripWS($StringInput, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) Local $StringInput = $sHTML Local $sHTML = StringReplace($StringInput, $Stuff, "") ;Local $StringInput = $sHTML ;Local $sHTML = StringReplace($StringInput, $Stuff2, "") Local $StringInput = $sHTML Local $ValutaPosition = StringInStr($StringInput, "</valuta>") Local $sHTML = StringTrimLeft($StringInput, $ValutaPosition+8) Local $StringInput = $sHTML ;StringReplace($StringInput, "<a xmlns="http://" ;Local $StringInput = $sHTML ;StringInStr ;Local $sHTML = StringTrimLeft($StringInput, 1850) ;Local $aDays = StringSplit($sHTML, ">datum</span>&gt;</a>") ;_ArrayDisplay($aDays) ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "StringRegExpReplace Error", "Error listing:" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(64, "HTML String?", "$sHTML:" & $sHTML) EndFunc ;==>InternetRead Edit: Sorry for the long post and I hope I was able to write dowm my problem in a way that others can understand, pls ask anything if you don't.
  9. Hey guys Can anyone help me explain this? $szFile = "test.htm" $szText = FileRead($szFile) $szText = StringReplace($szText, "hello", "ö") FileDelete($szFile) FileWrite($szFile,$szText) If the file "test.htm" has it's text changed into something containing non US characters, in this example "ö", the output is " ö " when shown in a browser. If i manually change the text in the "test.htm" file to "ö" - the output in the browser is "ö" ! In both cases, if the htm file is opened in notepad, the content is just "ö" - but the one changed from the script, still opens as " ö " in a browser. How weird is this? I am aware that I can replace the text to " &ouml;" , which is the HTML code for "ö" - then the output is correct in the browser, but this is just dumb when there are a lot of characters to be changed Does anyone know why this happens, and how to solve it in a more simple way?
  10. Hello. I need to perform a specific string replace, but not sure how to go about it. The scenario is this: I have a large block of text. Within the text colons appear ":", Sometimes the colons are used in a sentence appearing after a word. Other times they appear in between numbers like a ratio or a sport score (e.g. "6:8"). I want to replace the colons appearing between numeric values like 6:8 with the word "to", but not the ones appearing at the end of a sentence. Is there a way that I can have StringReplace (or any other method) differentiate when to replace the colon based on it appearing between numbers? I did try searching for a similar scenario. Thank you for any help.
  11. Im trying to edit a file, I want to find a string which has a line break in it, and replace it with a string that has multiple line breaks in it. editfile.txt looks like this: dog cat mouse chicken my au3 script looks like this but is not working, i suspect because of how I am trying to do the line breaks? Func EditFile($CurrentFile) $szFile = "$CurrentFile" $szText = FileRead($szFile,FileGetSize($szFile)) $szText = StringReplace($szText, "Cat" & @CRLF & "Dog", "Hippo" & @CRLF "Lion" & @CRLF & "Tiger") FileDelete($szFile) FileWrite($szFile,$szText) EndFunc ;--EditFile-- But once ran the file should look like this: Hippo Lion Tiger cat mouse chicken I cannot replace by line number as the animals are not in the same line in each copy of the file i want to run against. Can anyone help?
  12. Nothing amazing but I use it all the time, I'm surprised something similar hasn't been added to the standard StringReplace. I've never been any good at regular expressions, I'm sure if I was the whole example below could be done in one line But for the simple minded like me here you go Enjoy$BIOS = _StringMultiReplace(CleanWMIC("bios", "biosversion"), "(|)|{|}", "") Func _StringMultiReplace($zString, $zSearchString, $zReplaceString, $zDelimeter = "|") If $zString = "" OR $zSearchString = "" OR $zDelimeter = "" Then SetError(1) Return $zString EndIf $zArray = StringSplit($zSearchString, $zDelimeter) For $i = 1 to $zArray[0] $zString = StringReplace($zString, $zArray[$i], $zReplaceString) Next Return $zString EndFunc
  13. Hi, i wrote a script that can replace multiple strings in a xml file works fine but so slow! I've used StringReplace ,_ReplaceStringInFile, StringRegExpReplace, all the same very slow,. The number of replacements in the file about 8000 Any help would be greatly appreciated #include <File.au3> $path = @ScriptDir & '\xmlfo.xml' $OXML = FileOpen($path, 256) $XML = FileRead($OXML) $term = 'post' $nofr = 1 Local $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 3) FileClose($OXML) $XL = $XML If Not @error Then For $i = 0 To UBound($aArray) - 1 ;get data start ;ConsoleWrite ( $aArray[0] &' '&$i& @CRLF) $date = StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 3) If @error Then $date = StringRegExp("date err", "(.{33,}?(?:\s)|.+)", 3) ElseIf Not @error Then ;ConsoleWrite($date[0] & ' ' & $i & @CRLF) EndIf $kind = StringRegExp($aArray[$i], '(?i)<category>(.*?)</category>', 3) If @error Then $kind = StringRegExp("kind err", "(.{33,}?(?:\s)|.+)", 3) ;ConsoleWrite ( $kind[0] &' '&$i& @CRLF) ElseIf Not @error Then ;ConsoleWrite ( $kind[0] &' '&$i& @CRLF) EndIf If $kind[0] = $term And Data(getdate($date[0], 'year'), getdate($date[0], 'month')) = True Then _ReplaceStringInFile($path, $aArray[$i], '') If Not @error Then ;MsgBox(16,'',$XL) ConsoleWrite($nofr & ' ' & $i & @CRLF) $nofr = $nofr + 1 EndIf ;FileDelete(@ScriptDir & '\XML_output.xml') ;FileWrite (@ScriptDir & '\XML_output.xml', StringToBinary ( StringReplace($temp, $aArray[$i], "") , 4) ) Else ConsoleWrite ('err0x0'& @CRLF) EndIf Next EndIf
  14. Hi all, Im trying to replace a string with only relevant information. My first thought was the stringreplace function. The string i wish to cutdown: HospitalInfo.set2("HospitalInfoCash", "<b>Cash</b> - ","&euro;&nbsp;1,270,876"); The information i would like to keep is the cash amount: 1,270,876 From the helpfile: #include <MsgBoxConstants.au3> ; Replace a blank space (' ') with a - (minus) character. Local $sString = StringReplace("This is a sentence with whitespace.", " ", "-") Local $iReplacements = @extended MsgBox($MB_SYSTEMMODAL, "", $iReplacements & " replacements were made and the new string is:" & @CRLF & @CRLF & $sString) Now after some research i found out u cant use double quotes. So i searched the forum and found out u should wrap the double quotes into single quotes. So i tried to search on this for the replacement: HospitalInfo.set2('"'HospitalInfoCash'"', '"'<b>Cash</b> - '"','"'&euro;&nbsp;1,270,876"); Sadly, i am still getting a syntax error. Could someone point me in the right direction.
  15. I'm trying to replace all occurrences of one string in a binary file with another string (e.g. all "C:\" with "D:\"), but StringReplace() does nothing. I opened my files in Binary mode and set the data read in to binary(), but nothing works. My test script reads a compiled version of the script, does the replacements, then writes the results to an output file. Prior to calling StringReplace(), I call StringInStr() to see if my 'from' string is found. The StringInStr() reports that it found the string, but the StringReplace() reports 0 replacements. Just to be sure, I did a binary compare (BeyondCompare) and the input and output files were exactly the same. Here is my test code: #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Opt('MustDeclareVars', 1) _Main() Func _Main() Local $infn, $infh, $outfn, $outfh, $cnt, $str_from, $str_to Local $buffer, $offset = 0, $bufsize, $mcnt, $matches = 0, $ret $infn = StringTrimRight(@ScriptName, 4) & ".exe" $outfn = "test2_out.exe" $infh = FileOpen($infn, 16 + 0) If ($infh <= 0) Then Exit (1) $outfh = FileOpen($outfn, 16 + 2) ; 2 = Write mode (erase previous contents) If ($infh <= 0) Then Exit (1) $str_from = "D:\" $str_to = "C:\" $bufsize = 2000 While (1) FileSetPos($infh, $offset, 0) $buffer = FileRead($infh, $bufsize) If (@error == -1) Then ExitLoop $cnt = @extended $buffer = Binary($buffer) $ret = StringInStr($buffer, $str_from) If ($ret >= 0) Then ConsoleWrite("+++: 1 or more strings are in the buffer" & @CRLF) $buffer = StringReplace( _ $buffer, _ $str_from, _ $str_to _ ) $mcnt = @extended $matches += $mcnt ConsoleWrite("+++: " & $mcnt & " replacement(s) made" & @CRLF) FileWrite($outfh, $buffer) $offset += $cnt WEnd FileClose($infh) FileClose($outfh) ConsoleWrite("+++: matches: " & $matches & @CRLF) ConsoleWrite("+++: processed " & $offset & " bytes." & @CRLF) EndFunc ;==>_Main
×
×
  • Create New...