Jump to content

[help]Count, replace


Recommended Posts

Hi everybody :lol:

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" :graduated:

I don't know, but maybe: :oops:

FileDelete("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

WEnd

Hi 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 by ThiagoJunqueira
Link to comment
Share on other sites

  • Moderators

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 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

  • Moderators

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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

ThiagoJunqueira,

Simplified version with support for hex string added...

#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 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

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 Gude
How 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

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 mb

exe with hex compress > i don't know, but will be less.

This?

Orienta-te com o que procuras companheiro!

:S

Edited by careca
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...