ThiagoJunqueira Posted November 25, 2012 Share Posted November 25, 2012 (edited) Hi everybody Sorry for my english ..Well.. my doubt it's simples i guess, i want to replace some sequence of strings in texts, follow the example:"Posting aaa New Topic in Generaaaaal Help aand Suport"I have to replace a sequence of "a" to ", + numbers of sequence" then:"Poosting ,3 New Topic in Gener,4l Help ,2nd Suport" I don't know, but maybe: expandcollapse popupFileDelete("a.txt") $txt = "0a0000aaaaaa00000daga0gar0ga0g0a0gag0afgagga0000000gagag" $stxt= StringLen($txt) $qtd = 1 $add = 0 $we = 1 $posicao = StringInStr($txt, "0") While $posicao > 0 $se = StringTrimLeft($txt, $posicao) $se2 = StringTrimLeft($txt, $posicao + 1) if StringTrimRight($se, StringLen($se) - $qtd) = '0' then $we = 1 if StringTrimRight($se2, StringLen($se2) - $qtd ) = '0' Then While $we = 1 $add = $posicao & "," FileWrite("a.txt", $add & @CRLF) $posicao = $posicao + 1 FileWrite("a.txt", $add & @CRLF) ;~ StringReplace ;~ $we = 0 MsgBox(0, "", "te") WEnd Else FileWrite("a.txt", $add & @CRLF) EndIf EndIf if $posicao >= $stxt Then Exit EndIf $posicao = $posicao + 1 WEndHi again ):I really tried do this.I'm since 15 hours only trying, search on google..But i don't know how to do !!!Please help !The logic it's simples:Search a sequence of "0", "a", don't matter. and substitue for /numbersOFsequence.Please, somebody would help me ?Thanks ! Edited November 25, 2012 by ThiagoJunqueira Link to comment Share on other sites More sharing options...
ThiagoJunqueira Posted November 25, 2012 Author Share Posted November 25, 2012 Bump. Plaese help ): Link to comment Share on other sites More sharing options...
ThiagoJunqueira Posted November 25, 2012 Author Share Posted November 25, 2012 I changed the code.Sorry about flood, but i need thisBump ): Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2012 Moderators Share Posted November 25, 2012 ThiagoJunqueira, Please do nto bump your threads within 24 hrs - and certainly not overnight Sat-Sun when almost no-one is on the forum. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like this. I would do it this way: expandcollapse popup#include <String.au3> ; Here is the original string $sString = "Posting aaa New Topic in Generaaaaal Help aand Suport" ; Declare a couple of variables $iCount = 0 $sRev_String = "" ; Work backwards through the string For $i = StringLen($sString) To 1 Step -1 ; Read character $sChar = StringMid($sString, $i, 1) ; Test lowercase for case insensitivity - change this is you want to distinguish "A" and "a" Switch StringLower($sChar) Case "a" ; It is an "a" so increase the count $iCount += 1 Case Else ; It is something else If $iCount Then ; If the previous char was an "a" add the count to the string $sRev_String &= $iCount ; And reset the count ready for the next "a" $iCount = 0 EndIf ; Add the char to the string $sRev_String &= $sChar EndSwitch Next ; Now reverse the string we have created $sNew_String = _StringReverse($sRev_String) ; And here is the result ConsoleWrite($sNew_String & @CRLF) All clear? 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...
ThiagoJunqueira Posted November 25, 2012 Author Share Posted November 25, 2012 Hi M23, Thanks, really thanks (: Sorry for the bumps.. i was desperate The code is working fine *-* So short But when the "a" is more than 9, crash. Follow the example: $sString = "xaaaaaaaaaa" x01 ): I'm trying resolve this, but no progress Thanks Link to comment Share on other sites More sharing options...
kylomas Posted November 25, 2012 Share Posted November 25, 2012 (edited) TJ, This might get you started on a general string compressor (if that is what you are doing?). Code is rough but you'll get the idea. $str = 'a good boy doeees not ' & @crlf & _ 'do what goood boys doo not do ' & @crlf & _ 'However, goodd girls doooo ' & @crlf msgbox(0,'',simple_string_compression($str)) func simple_string_compression($string) local $new_string local $dupcnt for $i = 0 to stringlen($string) if stringmid($string,$i,1) = stringmid($string,$i+1,1) then $dupcnt += 1 continueloop Else If $dupcnt = 0 then $new_string &= stringmid($string,$i,1) ContinueLoop else $new_string &= '[' & stringmid($string,$i,1) & ',' & $dupcnt+1 & ']' $dupcnt = 0 EndIf EndIf Next return $new_string endfunc Spaces are not obvious due to the PS font used in MSGBOX. I changed the format of how dups are displayed. Good Luck, kylomas Edited November 25, 2012 by kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2012 Moderators Share Posted November 25, 2012 ThiagoJunqueira, It does nto crash - it just reverses the number! So we reverse it ourselves so that it comes out correctly in the final string: expandcollapse popup#include <String.au3> ; Here is the original string $sString = "Posting aaaaaaaaaaaa New Topic in Generaaaaal Help aand Suport" ; Declare a couple of variables $iCount = 0 $sRev_String = "" ; Work backwards through the string For $i = StringLen($sString) To 1 Step -1 ; Read character $sChar = StringMid($sString, $i, 1) ; Test lowercase for case insensitivity - change this is you want to distinguish "A" and "a" Switch StringLower($sChar) Case "a" ; It is an "a" so increase the count $iCount += 1 Case Else ; It is something else If $iCount Then ; If the previous char was an "a" add the reversed count to the string $iCount = _StringReverse($iCount) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sRev_String &= $iCount ; And reset the count ready for the next "a" $iCount = 0 EndIf ; Add the char to the string $sRev_String &= $sChar EndSwitch Next ; Now reverse the string we have created $sNew_String = _StringReverse($sRev_String) ; And here is the result ConsoleWrite($sNew_String & @CRLF) 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...
ThiagoJunqueira Posted November 25, 2012 Author Share Posted November 25, 2012 Hi guys. Thanks, i almost there *-* Yes, a string compressor. I don't know if will work, but the ideia is: Example hex: 4D5A90000300000004000000FFFF The ideia is compress de sequence number like, 0000, FFFF, C1C1C1 [...] After, the reverse program, will convert again to original "4D5A90000300000004000000FFFF", and create the .EXE, or open with RunPe This is possible ? Link to comment Share on other sites More sharing options...
kylomas Posted November 26, 2012 Share Posted November 26, 2012 ThiagoJunqueira, Are you trying to compress chars or a string representation of hex, these are different animals. Example hex: 4D5A90000300000004000000FFFF The ideia is compress de sequence number like, 0000, FFFF, C1C1C1 [...] What do you mean by "sequence number"? Backing up a little, why do you want to do this? There may be some other way to do what you want? kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted November 26, 2012 Share Posted November 26, 2012 (edited) ThiagoJunqueira, Simplified version with support for hex string added... expandcollapse popup#include <string.au3> $str = 'a good boy doeees not ' & @crlf & _ 'do what goood boys doo not do ' & @crlf & _ 'However, goodd girls doooo ' & @crlf $strhex = _stringtohex($str) msgbox(0,'',simple_string_compression($str)) msgbox(0,'',simple_string_compression($strhex,'hex')) msgbox(0,'',simple_string_compression('4D5A90000300000004000000FFFF','hex')) func simple_string_compression($string, $format='char') local $new_string local $dupcnt local $incr_value switch $format case 'char' $incr_value = 1 case 'hex' $incr_value = 2 case Else msgbox(17,'Parm ERROR','Specify either ''char''or ''hex'' in function call') exit endswitch for $i = 1 to stringlen($string) if stringmid($string,$i,$incr_value) = stringmid($string,$i+$incr_value,$incr_value) then $dupcnt += 1 if $incr_value = 2 then $i+=1 continueloop endif If $dupcnt = 0 then $new_string &= stringmid($string,$i,$incr_value) if $incr_value = 2 then $i+=1 ContinueLoop endif $new_string &= '[' & stringmid($string,$i,$incr_value) & ',' & $dupcnt+1 & ']' $dupcnt = 0 if $incr_value = 2 then $i+=1 Next return $new_string endfunc kylomas Edited November 26, 2012 by kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jmon Posted November 27, 2012 Share Posted November 27, 2012 @kylomas: That would be a great snippet to post in the snippet thread. [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
kylomas Posted November 27, 2012 Share Posted November 27, 2012 jmon, Feel free...I don't know what the protocol is for adding to that thread. kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ThiagoJunqueira Posted November 28, 2012 Author Share Posted November 28, 2012 Hi Sorry for the delay guysThe ideia is "compact" a EXE understand ? ?exe original > 1 mbexe with hex compress > i don't know, but will be less.I asked same people about that .. and they spoke that this is impossible ): Link to comment Share on other sites More sharing options...
BrewManNH Posted November 28, 2012 Share Posted November 28, 2012 Hex isn't going to make it smaller, in most cases it will be larger. Also, have you looked at using UPX or something similar? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
careca Posted November 28, 2012 Share Posted November 28, 2012 (edited) Tiago, what does this:Well.. my doubt it's simples i guess, i want to replace some sequence of strings in texts, follow the example:Search a sequence of "0", "a", don't matter. and substitue for /numbersOFsequence.Have to do with:The ideia is "compact" a EXE understand ? ?exe original > 1 mbexe with hex compress > i don't know, but will be less.This? Orienta-te com o que procuras companheiro!:S Edited November 28, 2012 by careca JScript 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe 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