Results 1 to 3 of 3

Thread: reverse the words

  1. #1

    reverse the words

    i want to send a letter to a friend but in reverse, not completely reversed ; but only the words: like: dear george how are you ---> you are how george dear, i come to the following way:
    type the normal message in the text box then click Run button
    Uses "UI"
    Dim MyMatrix() As String
    Dim nLines,i     As Long
    Dim tmpStr, txt As String 
    Global hDlg As DWord
    Function TBMain()
    Dialog New 0, "reverse the words", -1, -1, 300, 220, _
                                                      %WS_DLGFRAME Or %DS_CENTER Or %WS_CAPTION Or %WS_SYSMENU Or %WS_OVERLAPPEDWINDOW, _
                                                      0 To hDlg
     
    Control Add Textbox , hDlg, 3, "", 5,  20, 290, 200, _
                                               %ES_MULTILINE   Or _
                                               %ES_AUTOHSCROLL Or _
                                               %ES_AUTOVSCROLL Or _
                                               %WS_VSCROLL     Or _
                                               %WS_HSCROLL
    Control Add Button  , hdlg, 2,"Run",5,0,40,20
    Dialog Show Modal hDlg, Call dlgProc
    End Function 
    CallBack Function dlgProc() As Long 
    Select Case CBMSG
          Case %WM_COMMAND
            Select Case CBCTL
              Case 2
               tmpStr="" : txt=""
               Control Get Text CBHNDL, 3 To txt
               txt = TrimFull$(txt)
               nLines = Parse(txt, MyMatrix, " ")
               For i =nLines To 1 Step -1
                  tmpStr = tmpStr & MyMatrix(i) & " "
               Next
               'txt = txt & CRLF & "-----------" &  & CRLF & tmpStr
               txt = txt & CRLF & "-----------" & CRLF & tmpStr
               Control Set Text hDlg, 3, txt
     
            End Select
    End Select             
    End Function
    
    i have found TRIMFULL$ very usefull to reduce the many spaces to one, i was about to use regex but then have found this handy function. we must not use regular expressions but as a last resort for the complex pattern.
    i found also that writing "by mistake" & & such as:
    txt = txt & CRLF & "-----------" & & CRLF & tmpStr
    hangs the program instead of giving an error message.
    if there are other methods of reversing the words please post.
    regards
    Attached Files Attached Files

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Hi Zak,

    I posted the parser problem here:
    Bug report

    Thanks for your code, I also like to cypher messages sometimes


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Thanks Petr.

    This week I restarted to code on thinAir and thinBasic after my long heavy work load at office so I fix asap.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. RichEdit, searching & coloring words
    By zak in forum General
    Replies: 4
    Last Post: 31-08-2010, 14:15
  2. string reverse christmas :)
    By Lionheart008 in forum thinBasic General
    Replies: 0
    Last Post: 22-12-2009, 11:10

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •