Sign in to follow this  
Followers 0
Surviver

_Stringreverse problem

11 posts in this topic

I have a problem with _StringReverse() function.When i try to reverse the "{Enter}" the result is this:Posted Image

Instead, i want to pass to next line as it should be.

Share this post


Link to post
Share on other sites



AutoBot,

Use StringSpilt to get the text in each line, reverse each line in turn and then reassemble the whole: :mellow:

#include <GUIConstantsEx.au3>
#Include <String.au3>

$hGUI = GUICreate("Test", 500, 500)

$hEdit_1 = GUICtrlCreateEdit("", 10,  10, 480, 200)
$hEdit_2 = GUICtrlCreateEdit("", 10, 270, 480, 200)

$hButton = GUICtrlCreateButton("OK", 10, 220, 80, 30)

GUISetState()

GUICtrlSetData($hEdit_1, "This is the problem" & @CRLF)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sNewtext = ""
            $aLines = StringSplit(GUICtrlRead($hEdit_1), @CRLF, 1)
            For $i = 1 To $aLines[0]
                $sNewtext &= _StringReverse($aLines[$i]) &@CRLF
            Next
            GUICtrlSetData($hEdit_2, $sNewtext)
            GUICtrlSetState($hEdit_2, $GUI_FOCUS)
    EndSwitch

WEnd

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

The problem is that the EOL char on windows is CR + LF, and LF + CR is not recognized. You don't need to do what Melba tells you to do this time (:mellow:), instead do this:

StringReplace($sString, @LF & @CR, @CRLF)

Try that.

Share this post


Link to post
Share on other sites

Mat,

Did you actually test that idea - because it does not do what the OP wanted.

Take a look:

#include <GUIConstantsEx.au3>
#Include <String.au3>

$hGUI = GUICreate("Test", 500, 500)

$hEdit_1 = GUICtrlCreateEdit("", 10,  10, 480, 200)
$hEdit_2 = GUICtrlCreateEdit("", 10, 270, 480, 200)

$hButton = GUICtrlCreateButton("OK", 10, 220, 80, 30)

GUISetState()

GUICtrlSetData($hEdit_1, "This is the problem" & @CRLF)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sText = GUICtrlRead($hEdit_1)

            $sNewText = _StringReverse($sText)
            StringReplace($sNewText, @LF & @CR, @CRLF)

            GUICtrlSetData($hEdit_2, $sNewtext)
            GUICtrlSetState($hEdit_2, $GUI_FOCUS)
    EndSwitch

WEnd

I see no line return at the end of the reversed line as requested:

i want to pass to next line as it should be

30-15 I feel! :mellow:

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

This should satisfy everyone.

#include<Array.au3>
#Include <String.au3>
$aString = StringSplit(StringStripCR(GUICtrlRead($hEdit_1)), @LF, 2)
For $i = 0 To Ubound($aString) -1
    $aString[$i] = _StringReverse($aString[$i])
Next
GUICtrlSetData($hEdit_2, _ArrayToString($aString, @CRLF))

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

And just to prove the "there are 1000 ways to skin a cat" theory, here's a modification of Melba's with a single StringReverse() call (not that there is really any big advantage to that):

#include <GUIConstantsEx.au3>
#Include <String.au3>

$hGUI = GUICreate("Test", 500, 500)

$hEdit_1 = GUICtrlCreateEdit("", 10,  10, 480, 200)
$hEdit_2 = GUICtrlCreateEdit("", 10, 270, 480, 200)

$hButton = GUICtrlCreateButton("OK", 10, 220, 80, 30)

GUISetState()

GUICtrlSetData($hEdit_1, "This is the problem" & @CRLF & "And this is more" & @CRLF & "The end" & @CRLF)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exitloop
        Case $hButton
            $sNewtext = ""
            $aLines = StringSplit(_StringReverse(GUICtrlRead($hEdit_1)), @LF & @CR, 1)
            For $i = $aLines[0] to 1 Step -1
                $sNewtext &= $aLines[$i] & @CRLF
            Next
            GUICtrlSetData($hEdit_2, $sNewtext)
            GUICtrlSetState($hEdit_2, $GUI_FOCUS)
    EndSwitch
WEnd

Edit: remove quoted text

Edited by Spiff59

Share this post


Link to post
Share on other sites

Spiff59,

there are 1000 ways to skin a cat

My preferred version: :mellow:

"There are nine and sixty ways of constructing tribal lays,

And every single one of them is right!"

Rudyard Kipling - The Lost Legion, Stanza 1 (1895)

But then I am very fond of cats! :P

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

30-15 I feel! :P

In theory, practice and theory are the same. Once again it has been proved that they are not the same in practice.

Ah, but you're missing the error I pointed out earlier ... twice ... without it being fixed :party: I have no doubt I'll find some more errors by the end of the weekend.

:mellow:

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

i haven't understood nothing, i'm a beginner, but i can give the source of program and please tell me what i must modify.Here is source:

#include <GUIConstantsEx.au3>
#Include <string.au3>
#include<misc.au3>

Opt('MustDeclareVars', 1)
Opt("TrayMenuMode",-1)
_Main()

Func _Main()
   Local $filemenu,$exititem,$infoitem,$okbutton,$msg, $file,$curnumber1,$cur1, $cur4,$aboutitem,$iesi,$tsg,$Var1,$Var2

   GUICreate("Ducky's freaky Editor", 600, 600,10)
   $filemenu = GUICtrlCreateMenu("Meniu")
   $infoitem =GuiCtrlCreatemenuitem("Info",$filemenu)
   $exititem = GUICtrlCreateMenuItem("Iesire", $filemenu)
   $curnumber1 = guictrlcreateedit("",8, 8, 590, 249)
   guictrlcreatelabel("Scrie in coloana de sus "&@CR&" textul dorit si apasa ok", 140,270,190,30)
   $okbutton = GUICtrlCreateButton("OK",60, 270, 70, 20)
   TraySetIcon("info")
   TraySetState(4)
   $aboutitem      = TrayCreateItem("About")
   $iesi           = TrayCreateItem("Exit")
   GUISetState()

   While 1
      $msg = GUIGetMsg()
      $tsg = TrayGetMsg()
      Select
         Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
         Case $tsg = $aboutitem
             _about()
         Case $tsg = $iesi
             _iesi()
         Case $msg = $exititem
            ExitLoop
         Case $msg = $infoitem
            Msgbox(64,"Creator","Creat de Rising ACK @2010"&@CR&"www.hackpedia.info")
         Case $msg = $okbutton
            $cur1 = guictrlread ($curnumber1)
            $cur4 = _stringreverse ($cur1)
            guictrlcreateedit ($cur4, 8, 300, 590, 249)
    EndSelect

   WEnd

   GUIDelete()
   Exit
EndFunc
    func _about()
     Msgbox(64,"about:","Acest Text Editor"&@CR&"va inversa cuvintele scrise de dvs")
 EndFunc
 func _iesi()
     Exit
Endfunc

And thank you all for the pacience

Edited by AutoBot

Share this post


Link to post
Share on other sites

AutoBot,

i haven't understood nothing

And if you do not try to understand you will never progress.

Here is my solution commented - you try and adapt it to your source code (or didi you just copy it? :mellow: ):

#include <GUIConstantsEx.au3>
#Include <String.au3>

: Create a GUI

$hGUI = GUICreate("Test", 500, 500)

; Create the 2 edits and the button
$hEdit_1 = GUICtrlCreateEdit("", 10,  10, 480, 200)
$hEdit_2 = GUICtrlCreateEdit("", 10, 270, 480, 200)

$hButton = GUICtrlCreateButton("OK", 10, 220, 80, 30)

; Show the GUI
GUISetState()

; Fill the top edit with data
GUICtrlSetData($hEdit_1, "This is the problem" & @CRLF)

; Start the loop to keep the script active
While 1

    ; See if a control has been activated
    Switch GUIGetMsg()
        ; If it was the red [X] 
        Case $GUI_EVENT_CLOSE
            ; Then Exit
            Exit
        ; If it was the button
        Case $hButton
            ; Create an empty string
            $sNewtext = ""
            ; Get the text in teh top edit
            $sText = GUICtrlRead($hEdit_1)
            ; Split the lext into the individual lines
            $aLines = StringSplit($sText, @CRLF, 1)
            ; Now loop through these lines
            For $i = 1 To $aLines[0]
                ; Add the reversed line to the string and add a New Line
                $sNewtext &= _StringReverse($aLines[$i]) &@CRLF
            Next
            ; Set the new string into the bottom edit
            GUICtrlSetData($hEdit_2, $sNewtext)
            ; Give focus to the bottom edit
            GUICtrlSetState($hEdit_2, $GUI_FOCUS)
    EndSwitch

WEnd

Now go and read the Help file for each command and try to understand what is going on. If you are really lost, then you need to take a step back and start learning about AutoIt.

Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :P

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

Ok thank you for advices

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