Sign in to follow this  
Followers 0
ThiagoJunqueira

[help]Count, replace

15 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Bump.

Plaese help ):

Share this post


Link to post
Share on other sites

I changed the code.

Sorry about flood, but i need this

Bump ):

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hi M23,

Thanks, really thanks (:

Sorry for the bumps.. i was desperate

The code is working fine *-*

So short :D

But when the "a" is more than 9, crash.

Follow the example:

$sString = "xaaaaaaaaaa" x01 ):

I'm trying resolve this, but no progress

Thanks

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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 ?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hi :D

Sorry for the delay guys

The ideia is "compact" a EXE understand ? ?

exe original > 1 mb

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

I asked same people about that .. and they spoke that this is impossible ):

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 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
1 person likes this

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0